mysql - More nested while loops in PHP -


i tried pull data database need 2 while loops nest (fetch_assoc). problem inner loop doesn't loop gives me first element of array, array length times.

<?php     $al_num = $_get['album'];     $photo_query = "select photo album album_number={$al_num}";     $thumbnail_query = "select thumbnail album album_number={$al_num}";      $photo_result = mysqli_query($connection, $photo_query);     $thumbnail_result = mysqli_query($connection, $thumbnail_query); ?>     <?php while($photo = mysqli_fetch_assoc($photo_result)): ?>     <?php while($thumb = mysqli_fetch_assoc($thumbnail_result)): ?>         <li>             <a href="images/<?php echo $photo['photo'] ?>" class="highslide" onclick="return hs.expand(this, config1 )">             <img src="images/<?php echo $thumb['thumbnail'] ?>"  alt=""/>             </a>         </li> <?php endwhile; ?> <?php endwhile; ?> 

why not keep simple?

<?php     $al_num = $_get['album'];     // idea check $_get['album'] first ...     $photo_query = "select photo, thumbnail album album_number='".mysqli_real_escape_string ($connection, $al_num)."'";     $photo_result = mysqli_query($connection, $photo_query);      while(list ($photo, $thumb) = mysqli_fetch_row ($photo_result)) {         ?>         <li>             <a href="images/<?php echo $photo ?>" class="highslide" onclick="return hs.expand(this, config1 )">             <img src="images/<?php echo $thumb ?>"  alt=""/>             </a>         </li>         <?php     } ?> 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -