将2个WHERE语句放在一起

时间:2011-10-06 09:44:37

标签: php mysql sql

我在将两个陈述放在一起时遇到了问题

我目前的代码:

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 ";

由于某种原因,这不起作用。我没有得到任何结果我检查了数据库,并且有结果应该出来

5 个答案:

答案 0 :(得分:3)

您应该阅读有关sql语法的内容。在你用bool运算符放置任何数字条件之后。使用2次where不正确

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

答案 1 :(得分:3)

保留第二个WHERE表达式,它只是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"' ");

答案 2 :(得分:1)

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

答案 3 :(得分:1)

尝试:

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

答案 4 :(得分:1)

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

删除第二个WHERE