hello guys, just want to ask some newbie questions. i have a table named "students" in my database, the field names are "Lastname", "Firstname" and "Highschool". i want to view all records and sort my query by highschool field. i want to show that query results in a html table using php. how can i sort by showing all schools in the database and under each schools, i want all students' names that are in the same school. the highschool name is the header of the table and the content of that header will be the names of students under the name of the highschool. in the image that i provided, there are two tables of the school "Pasig Catholic College" i want that to become as one table and the names under that school is in the "Pasig Catholic College" table.
please help me with my codes.
here are the codes i use:
please help me with my codes.
here are the codes i use:
Code:
<?php
$query = "SELECT * FROM students ORDER BY highschool";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)) {
echo "<table border='1'>";
echo "<tr>";
echo "<th align='left'>" . $row['highschool'] . "</th>";
echo "</tr>";
echo "<tr>";
echo "<td width='450'>" . $row['lastname'] . ", " . $row['firstname'] . "</td>";
echo "</tr>";
echo "<p> </p>";
}
echo "</table>";
?>

Last edited: