gpt4 book ai didi

php - 从mysql表的多列中搜索值

转载 作者:行者123 更新时间:2023-11-29 21:06:35 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

(31 个回答)


5年前关闭。




enter image description here

我想匹配一个表的多个列中的一个值。但是当我执行我的代码时它返回错误
警告:mysql_fetch_array() 期望参数 1 是资源, bool 值在第 15 行的 C:\xampp\htdocs\srctravellers\php\searchbustiming.php 中给出

我的代码是:

$tocity=$_POST['tocity'];
$res=mysql_query("SELECT Route FROM routes where $tocity IN('City1','City2','City3','City4','City5','City6','City7','City8','City9','City10')");
while($result=mysql_fetch_array($res)){
echo $result['Route'];
}

这是我的表格列的快照

最佳答案

您必须使用 LIKE运算符(operator)在这里。

查询

$tocity=$_POST['tocity'];
$res=mysql_query("SELECT Route FROM routes where City1 LIKE '%$tocity%' OR City2 LIKE '%$tocity%' OR City3 LIKE '%$tocity%' OR City4 LIKE '%$tocity%' OR City5 LIKE '%$tocity%' OR City6 LIKE '%$tocity%' OR City7 LIKE '%$tocity%' OR City8 LIKE '%$tocity%' OR City9 LIKE '%$tocity%' OR City10 LIKE '%$tocity%' OR )");
while($result=mysql_fetch_array($res)){
echo $result['Route'];
}

关于php - 从mysql表的多列中搜索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36767454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com