i trying display data mysql table categories.
for example,
skill 1
-staff 1
-staff 2
skill 2
-staff 1
-staff 3
i managed display data database, however, shows multiple tables same skill , unable correct it.
edit: replies, have moved table codes out of while loop. however, shows table containing different skills , staff data clustered together. them categorized according skills, thank you!
here codes:
$result = mysql_query("select * acc_skills inner join accounts on accounts.role_id = acc_skills.fk_role_id inner join skills on skills.skills_id = acc_skills.fk_skills_id order skills.skills"); while ($row =mysql_fetch_array($result)){ echo' <b><font color="blue">'.$row['skills'].'   (skill id: '.$row['skills_id'].')</font></b>'; echo' <style>table, th, td {border: 1px solid black;}</style> <div class="table-responsive"> <table width="60%"> <thead> <tr> <th width = "20%" >engineer assign id</th> <th style="text-align:center" width = "40%">engineer</th> <th style="text-align:center" = "40%">skill level</th> <th> </th> </tr> </thead>'; echo '<tbody> <tr> <th scope="row" style="text-align:center">'.$row['acc_skills_id'].'</th> <td align="center">'.$row['name'].'  ('.$row['fk_role_id'].')</td> <td align="center">'.$row['level'].'</td> </td> </tr> </tbody>'; echo '</table><br><br>'; echo '</div>';
thanks in advance
you have check if skill_id has changed last processed row. if new skill_id appears, end current table , start new one.
<?php function tableheader() { echo '<div class="table-responsive">'; echo '<table width="60%">'; echo '<thead>'; echo '<tr>'; echo '<th width = "20%" >engineer assign id</th>'; echo '<th style="text-align:center" width = "40%">engineer</th>'; echo '<th style="text-align:center" = "40%">skill level</th>'; echo '<th> </th>'; echo '</tr>'; echo '</thead>'; echo '<tbody>'; } function tablefooter() { echo '</tbody>'; echo '</table>'; echo '</div>'; } tableheader(); $prevskillid = null; while ($row =mysql_fetch_array($result)){ if($row['skill_id'] != $prevskillid){ tablefooter(); tableheader(); } echo '<tr>'; echo '<td>'.$row[...].'</td>'; ...... echo '</tr>'; $prevskillid = $row['skill_id']; } tablefooter();
Comments
Post a Comment