PHP - Display SQL results in multiple tables -
i have db table student room assignments. each student has specific hall, floor, , apartment. need display each student in specific table results floor layout. below example. student id needs in correct apartment slot. there several id's per apartment. right lists them down page.
apartment 102 apartment 101
apartment 104 apartment 103
apartment 106 apartment 105
$query = "select res.id_num id, res.apartment residents res res.sess_cde = '$pulledsession' , res.room_assign_sts = 'a' , res.bldg_cde = '$pulledhall' , res.floor = '$pulledfloor'"; $result = odbc_exec($connect, $query); echo "<table style='padding:25;'> <tr> <th>apartment</th> <th>id</th> </tr>"; while(odbc_fetch_row($result)){ $id = odbc_result($result,id); $apartment = odbc_result($result,apartment); if ($apartment == $pulledfloor.'01') { echo "<tr >"; echo "<td>" . $pulledfloor.'01' . "</td>"; echo "<td>" . $id . "</td>"; echo "</tr>"; } else if ($apartment == $pulledfloor.'02') { echo "<tr>"; echo "<td>" . $pulledfloor.'02' . "</td>"; echo "<td>" . $id . "</td>"; echo "</tr>"; } else if ($apartment == $pulledfloor.'03') { echo "<tr>"; echo "<td>" . $pulledfloor.'03' . "</td>"; echo "<td>" . $id . "</td>"; echo "</tr>"; } else if ($apartment == $pulledfloor.'04') { echo "<tr>"; echo "<td>" . $pulledfloor.'04' . "</td>"; echo "<td>" . $id . "</td>"; echo "</tr>"; } else if ($apartment == $pulledfloor.'05') { echo "<tr>"; echo "<td>" . $pulledfloor.'05' . "</td>"; echo "<td>" . $id . "</td>"; echo "</tr>"; } else if ($apartment == $pulledfloor.'06') { echo "<tr>"; echo "<td>" . $pulledfloor.'06' . "</td>"; echo "<td>" . $id . "</td>"; echo "</tr>"; } } echo "</table>";
you need retrieve room number well. after that, 1 way load results associated array:
$rooms[$row['roomnumber']] = $resname; // example once have array built, can echo out table, either manually (build full table , echo each 1
echo "<tr><td>".$rooms['102']."</td><td>".$rooms['101']."</td></tr>"; or similar, or dynamically incrementing 2 room numbers in loop.
if have multiple students in room, tack on more depth array:
$rooms[$row['roomnumber']][] = $resname; then use loop in each cell echo out.
Comments
Post a Comment