Php MYSQL IN子句不工作
我使用了IN子句,但结果显示为空白,用于我使用的测试Php MYSQL IN子句不工作,php,mysql,mysqli,Php,Mysql,Mysqli,我使用了IN子句,但结果显示为空白,用于我使用的测试 category='computer' <body> <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); $data = mysql_query("SELECT * FROM informati
category='computer'
<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子句中使用它时,结果是空白的
<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>
你忘了信中的引号了
<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)
改用
<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')
您错过了列表中字符串值周围的单引号:
<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>
$data = mysql_query("SELECT * FROM information
WHERE title LIKE '%test%'
AND category IN ( 'computer', 'school', 'Hotel')");
计算机、学校、酒店应位于简单的海岸线内,例如(“计算机”、“学校”、“酒店”)。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果您选择PDO。
<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>