forTheDogs Posted March 5, 2008 Share Posted March 5, 2008 Hi! I have a dynamic photo page in my website. Each record in the database has fields for 8 photos but there is not always 8 photos. The result is a broken image link for each field with a NULL value and I am trying to get around this. My code right now is: <?php } // Show if recordset empty ?> <tr><td><?php if ($totalRows_rs_photos > 0) { // Show if recordset not empty ?> <table width="600" align="center" class="contentTable"> <?php $message=""; $photo1=$row_rs_photos['photo1']; $photo2=$row_rs_photos['photo2']; if(!empty($photo1)) { $message="<tr> <td><div align='center'><img src='images/db_images/".$row_rs_photos['call_name']."/" .$row_rs_photos['photo1']."' /></div></td> </tr>"; } if(!empty($photo2)) { $message="<tr> <td><div align='center'><img src='images/db_images/".$row_rs_photos['call_name']."/" .$row_rs_photos['photo2']."' /></div></td> </tr>"; } } ?> There is NOT a photo in $photo1 but there is one in $photo2. I know that it is properly accessing the record and the ? filter shows in the url address but the page only shows the page title which is the dog's call name from the record set but it does not show the second row which should be showing record 'photo2'. Please let me know if you can see what I am doing wrong. I am very new to php and mysql. Thanks!!! Quote Link to comment Share on other sites More sharing options...
fnairb Posted March 5, 2008 Share Posted March 5, 2008 try if(!is_null($photo1)) Quote Link to comment Share on other sites More sharing options...
craygo Posted March 5, 2008 Share Posted March 5, 2008 you can also make a for statement to loop through all the photofields <?php $message = ""; for($i=1; $i<=8; $i++){ if(!is_null($row_rs_photos['photo'.$i])){ $message .= "<tr> <td><div align='center'><img src='images/db_images/".$row_rs_photos['call_name']."/" .$row_rs_photos['photo'.$i]."' /></div></td> </tr>"; } } ?> Ray Quote Link to comment Share on other sites More sharing options...
forTheDogs Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks to you both for your help! These did not work though. Now when I load the page, the source code for this table is <table> </table> Nothing there!! I have continued to work with it for some time now. I completely started from scratch and redid the whole page to be sure there was nothing there causing a problem that I did not notice. First I just changed to !is_null. Then I used the "for" statement. This is where I am now with the same result: <?php $message=""; for($i=1; $i<=3; $i++) { // Start FOR if(!empty($row_rs_photos['Photo'.$i])) { //START if $message.= "<tr><td><div align='center'><img src='images/db_images/".$row_rs_photos['call_name']. "/".$row_rs_photos['Photo'.$i]."'></div></td></tr>"; } //end IF } //End FOR } //End Show if recordset not empty ?> I've verified that the photos are in the correct place. I moved the photo that was in Photo1 to Photo2 to make sure the script was not quitting entirely after it found the !error or !is_null in Photo1. Any other ideas? thanks! Quote Link to comment Share on other sites More sharing options...
amites Posted March 7, 2008 Share Posted March 7, 2008 have you tried checking isset ?? Quote Link to comment Share on other sites More sharing options...
forTheDogs Posted March 7, 2008 Author Share Posted March 7, 2008 I just tried isset but it is not working either. Thanks for the suggestion though! Quote Link to comment Share on other sites More sharing options...
forTheDogs Posted March 9, 2008 Author Share Posted March 9, 2008 I was able to make this work, although I don't understand why it did not work to begin with. I deleted the $message.="" Then instead of using $message to print out the script, I used "echo". for($i=1; $i<=3; $i++) { // Start FOR if(!empty($row_rs_photos['Photo'.$i])) { //START if echo "<tr><td><div align='center'><img src='images/db_images/".$row_rs_photos['call_name']. "/".$row_rs_photos['Photo'.$i]."'></div></td></tr>"; } //end IF } //End FOR } //End Show if recordset not empty Actually I should say this now works on my wamp server but not on my website. Quote Link to comment 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.