Jump to content

Rope

Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Rope's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The best I can do right now is with a modified version of wildteen's JOIN query, but it outputs a new instance of the band name for each release. Is this likely to be a JOIN issue?
  2. Thanks again guys. mjdamato gets what I'm aiming for, however there must be something slightly wrong in there as it blanks out in the browser (i'm testing online, no localhost available) I've modified wildteen88's code slightly and now I have it almost working. Only problem is it displays like this: name: BAND_1 releases: ALBUM_1 name:BAND_1 releases:ALBUM_2 --- name: BAND_2 releases: ALBUM_1 name:BAND_2 releases:ALBUM_2 --- Which is slightly wrong, as it should go: name: BAND_1 releases: ALBUM_1, ALBUM_2 name: BAND_2 releases: ALBUM_1, ALBUM_2 but I guess that's something to do with the while loop.
  3. wildteen88: your solution seems to be on the money, it'll take a bit of playing with for me to display the info correctly though (about two years since I did any serious PHP) lemmin: taking the if statement out results in all the 'release_name' results being echoed in the first instance of the outer loop, which is not quite right. hmm...
  4. Thanks guys, I'll try both of these right now.
  5. 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.
×
×
  • 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.