ec Posted April 27, 2008 Share Posted April 27, 2008 Any ideas on how to display the results of this query under the headings of Pupil Number, First Name, Lastname, Reason, and teacherid? $query = "SELECT detention.pupilno, detention.reason, detention.teacherid, pupil.firstname, pupil.lastname FROM detention, pupil WHERE detention.detentiondate = '$_SESSION[detentiondate]' AND pupil.pupilno = detention.pupilno "; $result = mysql_query($query); if ($result) { while ($array= mysql_fetch_assoc($result)) { echo "<br />"; print "$array[pupilno]: <i>$array[firstname] $array[lastname]</i><br />"; print "<b>Reason:</b> $array[reason]<br />"; print "<b>Allocated By:</b> $array[teacherid]"; print "<U> "; print "<b></u>[ ]</b><br />"; } } ?></p> Link to comment https://forums.phpfreaks.com/topic/103151-displaying-results-of-query-in-table/ Share on other sites More sharing options...
AndyB Posted April 27, 2008 Share Posted April 27, 2008 have a table header before the while ... echo the data out to html table rows and table data cells ... and close the table when the loop ends Link to comment https://forums.phpfreaks.com/topic/103151-displaying-results-of-query-in-table/#findComment-528380 Share on other sites More sharing options...
xcali Posted April 27, 2008 Share Posted April 27, 2008 hey here is a table im using currently if ud like u can modify it and use it ... ... ... $data = mysql_query("SELECT class_day, class_time, class_name, room_nr FROM classinfo WHERE class_name LIKE '%$courses%'"); $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but there aren't any classes avilable at this time<br><br>"; } else { echo "<table align='center' cellspacing='25' cellpadding='1' >"; echo "<tr> <td align='left'><b>Course Name</b></td> <td align='left'><b>Course Date</b></td> <td align='left'><b>Course Time</b></td> <td align='left'><b>Room Nr</b></td> while($result = mysql_fetch_array( $data )) { echo "<tr><td align='left'>" . $result['class_name'] . "</td> <td align='left'>" . $result['class_day'] . "</td> <td align='left'>" . $result['class_time'] . "</td> <td align='left'>" . $result['room_nr'] . "</td> } echo "</table>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/103151-displaying-results-of-query-in-table/#findComment-528383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.