Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if DB field has text and display if yes

Status
Not open for further replies.

coolicus

Programmer
May 15, 2007
50
GB
I am trying to check if my field has data, if it does then display the header and the text within the field.

Code:
<?php 
if(!($rs1['other']==0)) { 
echo "<b>Other </b><br /><br />" .
echo $rs1['other'];
}
?>

Can someone point out where I am going wrong? So what I tried to do was

1. check if field 'other' has data
2. if yes then display heading and data in field
3. if not then do nothing

Thanks
 
Code:
<?php 
if(!empty($rs1['other'])){
echo "<b>Other </b><br /><br />" .
echo $rs1['other'];
}
?>

in your usage you should try
Code:
<?php 
if($rs1['other'][red]![/red]==0) { 
echo "<b>Other </b><br /><br />" .
echo $rs1['other'];
}
?>
 
haha, I was just coming back to say don`t worry I have found the solution when you replied!

I used

if($rs1['other']<="")

is this ok, or would I be better using !==0?
 
empty() or !==

look at comparison operators in the php manual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top