Page 1 of 1

SQL sytax saying <>

Posted: Fri Jan 23, 2004 8:43 am
by pinehead18
I think you see what i'm trying to do. However i get parse errors each time i try.

Thanks

$sql .= "and 'mainpic' != \"default.gif\"";

I have also tried

Code: Select all

<?php
       $sql .= "and 'mainpic' != 'default.gif'";

?>

Code: Select all

<?php

Posted: Fri Jan 23, 2004 9:19 am
by twigletmac
Your field name shouldn't be in single quotes, you can either use backticks (` as opposed to ') or none at all. If you are using MySQL <> is the equivalent of !=:

Code: Select all

$sql .= "AND mainpic <> 'default.gif'";
The code you posted shouldn't cause a parse error though - what exactly was the error you got?

Mac

Posted: Fri Jan 23, 2004 5:52 pm
by pickle
I may be grasping at straws here, but will PHP parse the ".=" operator if $sql hadn't been set earlier?

Posted: Fri Jan 23, 2004 6:11 pm
by Sym
pickle wrote:I may be grasping at straws here, but will PHP parse the ".=" operator if $sql hadn't been set earlier?
It still will,

If the variable is not yet defined, it will create one and assign it to null so it will end up concatinating the string to a null value which will work fine.

However depending on your error_reporting level php might throw a NOTICE of an undefined variable.

Posted: Tue Jan 27, 2004 11:07 am
by Roja
twigletmac wrote:Your field name shouldn't be in single quotes, you can either use backticks (` as opposed to ') or none at all. If you are using MySQL <> is the equivalent of !=:
In MySQL both <> and != are valid and evaluated the same.