g3mma111 Posted August 14, 2007 Share Posted August 14, 2007 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.. Quote Link to comment https://forums.phpfreaks.com/topic/64846-solved-new-to-phphelp-with-query-please/ Share on other sites More sharing options...
micah1701 Posted August 14, 2007 Share Posted August 14, 2007 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$' Quote Link to comment https://forums.phpfreaks.com/topic/64846-solved-new-to-phphelp-with-query-please/#findComment-323571 Share on other sites More sharing options...
reages Posted August 14, 2007 Share Posted August 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64846-solved-new-to-phphelp-with-query-please/#findComment-323573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.