Jump to content

Recommended Posts

Hi Guys

 

I am using the following code to display data from three tables

<?php
      $gallery_sql=mysql_query("SELECT gallery_before.photo_id, gallery_before.photo_filename, gallery_before.photo_title, tbl_before_after.id, tbl_before_after.before, tbl_before_after.after, gallery_after.photo_id, gallery_after.photo_filename
                                       FROM tbl_before_after
                                       INNER JOIN gallery_before ON tbl_before_after.before = gallery_before.photo_id
                                       INNER JOIN gallery_after ON tbl_before_after.after = gallery_after.photo_id");
      if(mysql_num_rows($gallery_sql)==0)
      {
          echo("There are no photos to display in the gallery");
      }
      else
      {
      while($gallery_row=mysql_fetch_assoc($gallery_sql))
      {
          echo('<li><a href="photos/before/'.$gallery_row['gallery_before.photo_filename'].'" title=""><img src="photos/after/'.$gallery_row['gallery_after.photo_filename'].'" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/'.$gallery_row['gallery_after.photo_filename'].'"></a></li>');
      }
}
?>

 

and the view source is displaying the following results

 

<li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li><li><a href="photos/before/" title=""><img src="photos/after/" width="125" height="94" class="thumb"/></a></li><li><a href="photos/after/"></a></li>

 

Any ideas why the images are not displaying?

Link to comment
https://forums.phpfreaks.com/topic/238419-database-fields-not-being-displayed/
Share on other sites

Have done that, and below is an example of the result

 

Array

(

    [photo_id] => 3

    [photo_filename] => 3.jpg

    [photo_title] =>

    [id] => 4

    [before] => 3

    [after] => 3

)

 

Would the issue be because I am using fields with the same names but from different tables?

Remove the gallerybefore. and galleryafter. from your indexes.  Your dump shows that they are NOT in your array index.

"SELECT gallery_before.photo_id, 
              gallery_before.photo_filename, 
              gallery_before.photo_title, 
              tbl_before_after.id, 
              tbl_before_after.before, 
              tbl_before_after.after, 
              gallery_after.photo_id AS after_photo_id, 
              gallery_after.photo_filename AS after_photo_filename
                                       FROM tbl_before_after
                                       INNER JOIN gallery_before ON tbl_before_after.before = gallery_before.photo_id
                                       INNER JOIN gallery_after ON tbl_before_after.after = gallery_after.photo_id"

 

Now you should have a couple more indexes in that array.

I changed the query to

SELECT gallery_before.photo_id, gallery_before.photo_filename AS before_photo_filename, gallery_before.photo_title, tbl_before_after.id, tbl_before_after.before, tbl_before_after.after, gallery_after.photo_id, gallery_after.photo_filename AS after_photo_filename
FROM tbl_before_after
INNER JOIN gallery_before ON tbl_before_after.before = gallery_before.photo_id
INNER JOIN gallery_after ON tbl_before_after.after = gallery_after.photo_id

This got the desired results.

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.