Jump to content


Photo

How to check if database field is empty


  • Please log in to reply
1 reply to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 26 September 2006 - 09:51 PM

I have a field in my database which is used to hold the name of an image

What i want to do is have an if statement so if that field has got an image name in it then do this code

echo "<div id='right'><h3>".strtoupper($code['title'])."</h3><p class='style3' style='text-align:left'><i>Date added: ".$code['date']."</i></p><p class='style3'><img src=images/".$code['photo']." align='right' class='right'>".nl2br($code['content'])."</p><br></div>\n";

if the field is empty do this code

echo "<div id='right'><h3>".strtoupper($code['title'])."</h3><p class='style3' style='text-align:left'><i>Date added: ".$code['date']."</i></p><p class='style3'>".nl2br($code['content'])."</p><br></div>\n";

How do i check if the field is empty?
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 26 September 2006 - 09:56 PM

Something like this should do it:

if(!$code['photo']){
do this
}
else{
do that
}

the ! means "if the condition is false"

you could also use empty()

if(empty($code['photo'])){
do this
}
else{
do that
}
[/code]
If you're not part of the solution, you're part of the precipitate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users