i have some code which loops through a table, and displays the results. i have then added extra code so that it loops through another table, and prints out the reults, that are related to the first loop. so the page should look like
menu
submenu 1
submenu 2
submenu 3
menu 2
submenu 4 etc
The problem is that the code only prints out the first row from the first loop and nothing else.
<?php
$list = "SELECT * FROM section_main";
$result = mysql_query($list) or die ("Query failed");
$numofrows = mysql_num_rows($result);
echo "<table border='1' id='section_list'>";
echo "<tr><th>section_id</th><th>section_title</th></tr>";
for($j = 1; $j < $numofrows; $j++) {
echo '<tr>';
$row = mysql_fetch_array($result);
echo "<td>". $row['section_id'] . "</td><td>". $row['section_title'] . "</td>";
$query = "SELECT section_sub.section_sub_title, section_sub.section_title WHERE section_sub.section_title = " .$row['section_title']."ORDER BY section_sub_title";
$result2 = mysql_query($query) or die ("query failed2");//This part does not work
$numofrows2 = mysql_num_rows($result2);
for($i = 0; $i<$numofrows2; $i++){
$row2 = mysql_fetch_array($result2);
echo '<tr>'.$row2['section_sub_title'].'';
}
}
echo "</tr>";
echo '</table>';
?>
i havnt completed all of the html yet, i just wanted to get the php working. any ideas on why the query failed?
Any help on whats wrong would be great