Jump to content

[SOLVED] New to PHP....help with query please!


g3mma111

Recommended Posts

I am trying to get records from the database where the username= $username and the comment does not equal $comment. Ive heard != means not equal so this is what i have so far:

 

 $sql="select * from comments where (tousername= '$username') AND (commment != $comment) ORDER by date";

 

im not sure if its meant to be in brackets??? I basically dont have a clue what im doing..

Link to comment
https://forums.phpfreaks.com/topic/64846-solved-new-to-phphelp-with-query-please/
Share on other sites

unless $comment is a number, you need single quotes around it

 

comment != '$comment'

 

also, sometimes it works better to use NOT LIKE instead.

 

comment NOT LIKE '$comment'

 

this also lets you throw in some wildcard, like:

 

comment NOT LIKE '%$comment$'

check your comment comparison... isn't it supposed to be string?

 

instead of:

$sql="select * from comments where (tousername= '$username') AND (commment != $comment) ORDER by date";

try

$sql="select * from comments where (tousername= '$username') AND (commment != '$comment') ORDER by date";

 

also, don't forget to check for other syntax, such as spelling. commment?

 

regards.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.