-1

Suppose I have a table named "farmstuff" like this highly simplified and strange looking one;

id  mark        pjob        role        jobDesc 
1    1        horses        Smithy      Smith Stuff 
1    1        horses        Smithy      More Smith stuff
1    1        horses        Smithy      Even More Smith stuff
2    1        cows         Farrier      Put left front shoe on
2    1        cows         Farrier      Put right front shoe on

And my PHP to read it is like this:

 <?php
 $tableheader = "<table><thead><tr><th>col3</th><th>col4</th></tr></thead><tbody>";
 $sql = "SELECT id, mark,  pjob, role, jobDesc FROM farmstuff WHERE mark = 1 ORDER BY id";
     $echo($tableheader);
     foreach($found->query($sql) as $row) {
         echo ("<tr>");
     }
         echo("<td>$row[role]</td>");
         echo("<td>$row[jobDesc]</td>");
     }   echo("</tr></tbody></table>");
 ?>

And what I want is two tables like below. Despite the values of the other variables, I want to break the tables at the change in value of id. So if its 1 then the first title is horses, if its 2 then the title is cows. Keep in mind these are tables now. So first how do I create two tables from the output of the SQL with the appropriate break, and second how should I put the label on top of each as in the example below?

horses
col4        col5
Smithy      Smith Stuff
Smithty     More Smith Stuff
Smithy      Even More Smith Stuff
cows
col4        col5
Farrier     Put left front shoe on
Farrier     Put right front shoe on
Keith D Kaiser
  • 1,016
  • 2
  • 14
  • 31
  • I got the answer I needed so no big deal bu I'm not sure at all how Mr. Barmar sees my question and the other as the same thing? First you can hardly even read the other question. English is clearly not his first language. So what, I don't care about that. I think Mr. Barmar just want one more point. – Keith D Kaiser Oct 13 '15 at 13:41

1 Answers1

1

This isn't tested (more of a prototype), but something like this:

<?php
 $tableheader = "<table><thead><tr><th>col3</th><th>col4</th></tr></thead><tbody>";
 $sql = "SELECT id, mark,  pjob, role, jobDesc FROM farmstuff WHERE mark = 1 ORDER BY id";
     $echo($tableheader);
     $lastid = '';
     foreach($found->query($sql) as $row) {
         if($lastid != $row[role]) {
           echo ("<tr><td colspan=2>$row[id]</td></tr>");
         }
         echo ("<tr>");
         echo("<td>$row[role]</td>");
         echo("<td>$row[jobDesc]</td>");
         echo("</tr>");
         $lastid = $row[role];
     }
     echo("</tbody></table>");
 ?>
Michael Y.
  • 661
  • 7
  • 12