SQL sytax saying <>

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

SQL sytax saying <>

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I may be grasping at straws here, but will PHP parse the ".=" operator if $sql hadn't been set earlier?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Sym
Forum Newbie
Posts: 3
Joined: Fri Jan 23, 2004 1:05 pm
Location: Vancouver, B.C.

Post 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.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
Post Reply