PDA

View Full Version : if statement not working



Aravona
07-19-2010, 01:29 PM
I have a site which I need to display a table based on a boolean in my database, basiacally if the product has accessories or not.



$sql = "SELECT accessory FROM ver_pro where pID='1' AND prCode = '1000107'";
$result = mysql_query($sql);
$query_data = mysql_fetch_assoc($result);
if ($query_data == 1){
//display code
}
else {
echo 'fail';
}


However all I get is the fail. I have double checked the SQL and phpmyadmin beings back Accessory as 1 which is what I expected, but I don't seem to be able to show the extra code based on this boolean... and it just lags the page out a lot and displays a blank page or a 'cannot display page' if the code is wrong, no errors even and errors are turned on.

Any help would be awesome,

Thanks in advance

Aravona

djr33
07-19-2010, 02:10 PM
It never should be equal to one. It will be equal to data. You could use !==FALSE.

airjordanshoes
07-22-2010, 07:44 AM
[spam removed]

fastsol1
07-22-2010, 12:55 PM
Could it be that in your string for the query your 'where' isn't WHERE? DJR33 - is that correct that it should always be in uppercase or it won't read it right?

bluewalrus
07-22-2010, 01:13 PM
No, the where doesn't need to be capitalized or at least no in DBs I've worked with. Air Jordans haha that's some nice random spam placement.

I assume djr's solution fixed the problem.

djr33
07-22-2010, 01:50 PM
It doesn't need to be uppercase, though I find it easier to read and thus more likely to work (less chance of a typo, etc). Same with the `tablename` with the backticks. It's not required, but in some cases that one actually can matter. Usually it's not important, but I always use it just to have consistent code.