php - Split ID's Up In Tables In While Loop -


i have following database table:

award_id   |  nominee_id   |  voter_id  |  multi_code ------------------------------------------------------ 5          | 3             |  1         |  9326 5          | 4             |  1         |  9326 5          | 5             |  3         |  8746 

i need display these results in tables grouped multi_code, example:

so like

<h1>multi code: 9326</h1> <table> <tr> <td>nominee: 3</td><td>nominee: 4</td> </tr> </table>  <h1>multi code: 8746</h1> <table> <tr> <td>nominee: 5</td> </tr> </table> 

here sql + php far:

$nomineedetails = mysqli_query($con,"select award_id, nominee_id, voter_id, multi_code  b_awards_votes award_id = '5'"); $multi_code = -1; while($row = mysqli_fetch_array($nomineedetails)) { $awardid = $row['award_id']; $nomineeid = $row['nominee_id']; $voterid = $row['voter_id']; $multicode = $row['multi_code'];  print "<h2>$multicode</h2>";  if ($multi_code != $multicode) {  print "<table><tr>";  $multi_code = $multicode; }  print "<td>nominee: $nomineeid</td>";";  } </tr></table> 

with this:

 8746   9326   nominee: 3   9326   nominee: 4 nominee: 5 

why getting 9326 above nominee 3?

first of all, suggest order results multi_code have correct sorting when looping through results.

then, in loop print headline multi code, regardless being different previous one.

please have @ code. isn't tested, please aware there might errors in it:

$nomineedetails = mysqli_query($con,"select award_id, nominee_id, voter_id, multi_code  b_awards_votes award_id = '5' order multi_code asc"); $multi_code = -1; while($row = mysqli_fetch_array($nomineedetails)) {     $awardid = $row['award_id'];     $nomineeid = $row['nominee_id'];     $voterid = $row['voter_id'];     $multicode = $row['multi_code'];      if ($multi_code != $multicode) {         if($multi_code !== -1) {             print "</table>";         }         print "<h2>$multicode</h2>";         print "<table>";          $multi_code = $multicode;     }      print "<tr><td>nominee: $nomineeid</td></tr>"; } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -