title: while inside of another while in PHP using MySQL
body: <p>I need to do the following - get the list of all artists from the database and print them on a page. But besides of that, I need to make another query to the "albums" table and get the albums of each artist and print the images under each artist description. The code I've written is as follows:</p>
  
  <pre><code>require('db.php');
  
  $query = "SELECT * FROM artists";
  $result = mysql_query($query);
  
  $artist_id = $result[id];
  $artist_name = $result[name];
  $artist_surname = $result[surname];
  $artist_email = $result[email];
  $artist_about = $result[about];
  $artist_photo = $result[photo];
  while(list($artist_id, $artist_name, $artist_surname, $artist_email, $artist_about, $artist_photo) = mysql_fetch_row($result)) :
      print "&lt;div class='row'&gt;";
      print "&lt;div class='artists_left'&gt;";  
      print  "&lt;div class='gallery_cont'&gt;&lt;a href='#'&gt;&lt;img src='timthumb.php?src=images/artists/$artist_photo&amp;w=240&amp;h=318' alt='$artist_name' /&gt;&lt;/a&gt;&lt;/div&gt;";
      print  "&lt;/div&gt;";  
      print "&lt;div class='artists_right'&gt;";
      print   "&lt;div class='artist_title_cont'&gt;&lt;span class='model'&gt;Художник:&lt;/span&gt;&lt;span class='name'&gt;$artist_name $artist_surname&lt;/span&gt;&lt;span class='mypage'&gt;Личная почта:&lt;/span&gt;&lt;a href='#' class='mypage'&gt;$artist_email&lt;/a&gt;&lt;/div&gt;";
      print   "&lt;div class='artist_title_cont' style='margin-top:20px;'&gt;&lt;span class='name'&gt;$artist_about&lt;/span&gt;&lt;/div&gt;";
      print     "&lt;ul class='artists'&gt;";
      $albums_query = "SELECT id, title_photo, dirname FROM albums WHERE master = $artist_id";
      $albums_result = mysql_query($albums_query);
      $album_id = $albums_result[id];
      $album_photo = $albums_result[title_photo];
      $album_dirname = $albums_result[dirname];
      while(list($album_id, $album_photo, $album_dirname) = mysql_fetch_row($result)) :   
          print "&lt;li&gt;&lt;a href='#'&gt;&lt;img src='galleries/$album_dirname/$album_photo' alt='image' /&gt;&lt;/a&gt;&lt;/li&gt;";
      endwhile;
      print "&lt;/ul&gt;";
      print      "&lt;a href='#' class='seemore_portfolio'&gt;все работы мастера &amp;gt;&lt;/a&gt;";
      print  "&lt;/div&gt;";    
      print "&lt;/div&gt;";
  endwhile;
  mysql_close($connect);
  </code></pre>
  
  <p>The outer query works fine, but the inner one - does not. Could anybody help me to figure this out?</p>
  
  <p>Thanks in advance.</p>