Jump to content

Loop Problem


proctk

Recommended Posts

Hi

 

The below code gets album names from one table then looks in another table of the files that belong in that album.  The problem that I'm having is if there is nothing in the table image_files then the data from the table album does not show.  I want it to show the album even if its blank. the data would show and the spot for the image would be blank.

 

thankyou for any help

 

thank you

 

<?php 
  // get photo albums
   $query_get_albums_name = ("SELECT * FROM albumNames WHERE user_id = '$user_id'");
   $get_albums_name = mysql_query($query_get_albums_name)or die("SQL Error: $query_get_albums_name<br>" . mysql_error());
  while($albums_name = mysql_fetch_assoc($get_albums_name)){
  
  $foundAlbum = $albums_name['album'];

  //Get & group photos
$query_get_albums = ("select * from image_files WHERE user_id = '$user_id' AND album = '$foundAlbum' GROUP BY `album`");
$get_albums = mysql_query($query_get_albums)or die("SQL Error: $query_get_albums<br>" . mysql_error());	 	   
  while($album=mysql_fetch_assoc($get_albums)) { 
  
     $query_photo_count = mysql_query("SELECT * FROM `image_files` WHERE `album` = '$album[album]'") or die(mysql_error());
  $photo_count=mysql_num_rows($query_photo_count);
  ?>
  <table class="columntable" style="border:3px solid #EBEBEB;">
  <tr>
    <td rowspan="6" style="width:25%; padding-right:10px; padding-left:10px;"><img src="../user_images/<?php echo $album['image_name']; ?>" width="150" height="110" alt="<?php echo $album['image_name']; ?>"/></td>
    <td style="width:75%; color:
#5e49d9; font-weight:bold; font-size:16px;"><?php echo $album['album']; ?></td>
  </tr>
  <tr>
    <td style="color:#C4C4C4; font-style:italic;"><?php echo $photo_count;  ?> photos</td>
  </tr>
  <tr>
    <td><?php echo $albums_name['albumDetails']; ?></td>
  </tr>
  <tr>
    <td>Location:<?php echo $albums_name['location']; ?></td>
  </tr>
  <tr>
    <td>Create Date: <?php echo $albums_name['createdate']; ?> </td>
  </tr>
  <tr>
    <td><a href="#">Edit Album</a> | <a href="#">Veiw Album</a></td>
  </tr>
</table>
<?php }
   }?>

Link to comment
Share on other sites

Your syntax is wrong in your sql statement.

 


$query_get_albums = ("select * from image_files WHERE user_id = '$user_id' AND album = '$foundAlbum' GROUP BY `

 

should be

 

 

// I don't know what criteria you wanted to group by so I chose user_id but you were missing

// a double quote and a parenthesis. You don't need to use parenthesis but if you use one you

// need to close it with another.

 


$query_get_albums = ("SELECT * from image_files WHERE user_id = '$user_id' AND album =
'$foundAlbum' GROUP BY user_id");

 

good luck

 

Link to comment
Share on other sites

woops I didn't see the scroll bar, but here's another error.

 


query_photo_count = mysql_query("SELECT * FROM `image_files` WHERE `album` = '$album[album]'")

 

lose the single quotes around image_files and album like this.

 


query_photo_count = mysql_query("SELECT * FROM image_files WHERE album = '$album[album]'");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.