开发者

Putting 2 WHERE statements together

I'm having problems putting two where statements together

My current code:

include 'config.php'; 

$result22 = mysql_query("SELECT * FROM messages WHERE to_user='".$_SESSION['username'].开发者_运维知识库"'     AND to_read_yet='yes' ");


$num_rows22 = mysql_num_rows($result22);


echo "$num_rows22 ";

For some reason this isn't working. I am not getting any results i have checked the db and there are results which should come out


You should read about sql syntax. After where you put any number conditions with bool operators. Using 2 times where is incorrect

$result = mysql_query("SELECT * FROM messages WHERE to_user='".$_SESSION['username']."'     AND to_read_yet='"no"' ");


Leave the second WHERE expression out, it's just WHERE condition_1 AND condition_2 AND condition_3 AND ....

$result = mysql_query("SELECT * FROM messages WHERE to_user='".$_SESSION['username']."' AND to_read_yet='"no"' ");


SELECT *
FROM messages
WHERE to_user = '".$_SESSION['username']."'
  AND to_read_yet= '"no"'


try with:

$result = mysql_query("SELECT * FROM messages WHERE to_user='".$_SESSION['username']."'     AND to_read_yet='no' ");


$result = mysql_query( "SELECT * FROM messages WHERE to_user='" . $_SESSION['username'] . "' AND to_read_yet='no'" );

Drop the second WHERE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜