Jump to content

using *if(!empty($photo1)) * in web page so null value mysql record is ignored


forTheDogs

Recommended Posts

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!!!

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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.

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.