Forum Moderators: coopster

Message Too Old, No Replies

if else dependent on variable in sql

if else dependent on variable in sql

         

Riot_RCR

5:08 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



I am trying to have php talk to sql and depending on if there is somthing in the db have it display one image or the other.

I have filesize default to 0 if nothing is put in. I have no idea what I am doing and after hackin' this for the better part of 3 days...I figured I better start asking for help...


$dbh=mysql_connect ("localhost", "un", "pw") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("rcracin_slips");
$query="select * from binary_data";
$rt=mysql_query($query);
echo mysql_error();

while($nt=mysql_fetch_array($rt)){
if ($nt = 0 ) {
echo "$nt[filesize] <br /><br />";
}
else {
echo "nothing<br /><br />";
}
}


I am sure there is prob an easy way to do this, but I have no sql experiance, and very very little php experiance. Thanks in advance for any help.

Anyango

6:25 pm on Feb 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I never loop like that (just a personal preference) but i think it could be following two reasons your code isnt working

first of all


if ($nt = 0 )

i think that should be

if ($nt[filesize]=0)

second, in a Comparison statement, Double Equal signs should be coded, 1 = sign means assignment and 2 = signs mean comparison

so it should be


if ($nt[filesize]==0)

see if it works?

Riot_RCR

7:43 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



That did the trick! Thanks, I was close...

Yeah the code is a bit of a mess, but as I said I am new to this...but I will get better.

Thanks again!

coopster

4:25 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Just for reference:
Assignment Operators [php.net]
Comparison Operators [php.net]

And welcome to WebmasterWorld, Riot_RCR :)