sql not equal

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
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

sql not equal

Post by psychotomus »

Code: Select all

$sql = mysql_query("SELECT id, url, title, descriptionFROM {$prefix}pages WHERE category = $c AND accepted = 'y' AND subtype != '4' ORDER BY title LIMIT ".($s-1).",$n");

whats wrong with this. It will work fine without subtype != '4'. should it be <> instead or NOT or what?

Jcart | Please use

Code: Select all

tags when posting php code. Review   [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

did you try it?

it should be "<>", but you gotta try it to know :?
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

neither work but i did an alternative way.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

heres a list of symbols

specifically
!= (not equal), Comparison Functions and Operators
Perhaps show us your table structure? I don't see anything obvious why it wouldn't work.. but I might just have missed it.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Code: Select all

$var = (0 !== false)
//true
$var = (0 != false)
//false
EDIT- Err... maybe that's not what he meant.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

remove the curly brackets in your SQL statement. If you want to insert variable values, a clean way would be:

Code: Select all

"SELECT me FROM thousands WHERE ".$i."<>'you'";
Post Reply