alconebay Posted April 4, 2008 Share Posted April 4, 2008 OK, I have a database with fields for name, web, and phone. I'm making a directory page that displays the information, but I want to display only the name and website. However, if the person does not have a web site I want it to display their phone number instead. Here is the section I'm having problems with: <? echo $name; ?> - <? if ($web==0) {echo $phone;} else {echo $web;} ?> I have a loop set up so it pulls all the people in the directory but here is what displays on the page (no matter if they have a website or not): "The persons name" - "The persons phone" I was under the impression that "($web==0)" means "If the website field is empty" but I must be wrong. Quote Link to comment Share on other sites More sharing options...
alconebay Posted April 4, 2008 Author Share Posted April 4, 2008 I spoke too soon. I just found this page: http://us.php.net/empty is got my answer: <? echo $name; ?> - <? if (empty($web)) {echo $phone;} else {echo $web;} ?> Quote Link to comment Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 yes there is look here http://php.net/manual/en/types.comparisons.php Ray Quote Link to comment Share on other sites More sharing options...
haku Posted April 4, 2008 Share Posted April 4, 2008 Two side points: 1) Don't use <? use <?php <? isn't supported by some servers, and your own server could change the settings one day unexpectedly, and your script wont work anymore. 2) You can change this: if (empty($web)) {echo $phone;} else {echo $web;} To this: echo (empty($web)) ? $phone : $web; Its shorthand that accomplishes the same thing. Not at all necessary, but a more compact piece of code if you want to use it! Quote Link to comment Share on other sites More sharing options...
alconebay Posted April 4, 2008 Author Share Posted April 4, 2008 Thanks for the help, I'll use those tips. 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.