我用了IN子句但是结果显示空白,我用过测试
category='computer'
它有效,但是当我将它与 IN 子句一起使用时,结果为空白
<body>
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
$data = mysql_query("SELECT * FROM information WHERE title LIKE '%test%' AND category IN ( computer, school, Hotel)");
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['id'];
echo $result['title'];
echo"</br>";
} ?>
</body>
</html>
最佳答案
你忘了引号
IN ( computer, school, Hotel)
改为使用
IN ( 'computer', 'school', 'Hotel')
关于php - MYSQL IN 子句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24899654/