Page 1 of 1

if $logo == "0" do this

Posted: Sun Aug 28, 2005 2:16 pm
by ianhull
Hi Guys,

I am trying to display logos on my page but some of the records do not have logos and this has placed a "0" in my db.

I have tried using this but with no luck

<?php
$nothing = "0";
{
if ($logo == $nothing){
$logo = "nopic.jpg";
} else {
$logo = $logo;
}
} ?>

Does anyone know how to achieve this?

Thanks

Posted: Sun Aug 28, 2005 2:31 pm
by jayshields
youve got the right idea but try setting $nothing to 0 like this...

Code: Select all

$nothing = 0;
instead of

Code: Select all

$nothing = "0";
because the way you are doing it now it is looking for a string - atleast i think that is the problem, worth a try anyway.

Posted: Sun Aug 28, 2005 2:45 pm
by feyd
may want to use empty()

Posted: Sun Aug 28, 2005 3:00 pm
by ianhull
Thanks Guys,

I still have not managed to get it working due to being a noobie with php but I will mess with it and see if I can work it out.

Thanks for your help.

Posted: Sun Aug 28, 2005 3:11 pm
by feyd
what about updating the database records to use NULL or an empty string?

Posted: Sun Aug 28, 2005 4:34 pm
by ianhull
Thanks for the suggestion.

I have now managed to get it to work with the empty() you suggested.

Thanks

Posted: Sun Aug 28, 2005 7:49 pm
by harrisonad
whenever $logo has a value of false or 0, you can simplify your condition to this

Code: Select all

if($logo){
// or the reverse
if(!$logo){