bravo14 Posted June 4, 2011 Share Posted June 4, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238419-database-fields-not-being-displayed/ Share on other sites More sharing options...
teynon Posted June 4, 2011 Share Posted June 4, 2011 before the echo, put "print_r($gallery_row);" Quote Link to comment https://forums.phpfreaks.com/topic/238419-database-fields-not-being-displayed/#findComment-1225256 Share on other sites More sharing options...
bravo14 Posted June 5, 2011 Author Share Posted June 5, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238419-database-fields-not-being-displayed/#findComment-1225274 Share on other sites More sharing options...
jcbones Posted June 5, 2011 Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238419-database-fields-not-being-displayed/#findComment-1225281 Share on other sites More sharing options...
bravo14 Posted June 5, 2011 Author Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238419-database-fields-not-being-displayed/#findComment-1225387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.