Hi all. Apologies if this has been asked, but I really can't find a solution.
I have a while loop inside another, and both are using data from separate mysql tables.
<?php
//Connect to Db
include('library/db_connect.php.inc');
//Select all rows from main table where visible = 1, alphabetical order
$main_all = mysql_query("SELECT * FROM main WHERE visible = 1 ORDER BY name");
//Count number of rows in main table
$num_rows = mysql_num_rows($main_all);
//Get all rows from releases table
$releases_all = mysql_query("SELECT * FROM releases");
//Include header
include('header.php.inc');
//Loop to output all rows
while ($row = mysql_fetch_array($main_all)) {
//Start band div
echo("<div class=\"BandListItem\">");
//Releases
echo("\n<p class=\"Releases\">Releases: ");
//While loop to pull releases that match the band id
while($release_row = mysql_fetch_array($releases_all)) {
$release_array = array($release_row['release_name'], $release_row['band_id']);
if ($release_array[1] == $row['id']) {
echo $release_array[0] . $release_array[1] . ", ";
}
}
echo("</p>");
//Close band div
echo("</div>");
}
//Include right col and footer
include('footer.php.inc');
?>
What's meant to happen is that the second while loop pulls the 'release_name' and 'band_id' from one table, but only echos the info if the 'band_id' matches the 'id' from the other table.
What actually happens is that the first loop is completed every time but the second one is only completed once. What the inner loop echos is fine, but it doesn't do it for every instance of the outer one.
I've tried resetting the array (read up about that) and I've tried changing the 'while' loop to a foreach statement but to no avail.
There's an example I thought would help on the php.net 'while' entry, but that didn't work either.
Any suggestions would be appreciated.