Jump to content

Displaying Results of Query in Table


ec

Recommended Posts

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

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>";
			 }
}
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.