Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MYSQL IN子句不工作_Php_Mysql_Mysqli - Fatal编程技术网

Php MYSQL 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

我使用了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 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>