开发者

Putting 2 WHERE statements together

开发者 https://www.devze.com 2023-04-11 07:50 出处:网络
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\'].开发

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

精彩评论

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