if $logo == "0" do this

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

if $logo == "0" do this

Post 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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

may want to use empty()
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what about updating the database records to use NULL or an empty string?
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Thanks for the suggestion.

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

Thanks
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post 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){
Post Reply