简体   繁体   English

如何遍历mysqli查询结果?

[英]how to loop through mysqli query results?

hi im using the following code to display all the query results but its just giving me one 您好,即时通讯使用以下代码来显示所有查询结果,但它只是给我一个

$do_search=mysqli_query($conx, "SELECT * FROM `vehicles` WHERE `$op` LIKE '%$search%'");
 while ($row = mysqli_fetch_array($do_search)) 
 {
     echo $row['model'];
 }

this code works fine giving me 2 results but when i use 这段代码可以很好地给我2个结果,但是当我使用

$do_search=mysqli_query($conx, "SELECT * FROM `vehicles` WHERE `$op` LIKE '%$search%'");
 while ($row = mysqli_fetch_array($do_search)) 
 {
     echo $row['id'];
 }

it gives me only one result why? 它只给我一个结果,为什么?

output for first code: 第一个代码的输出:

xk-1 xk-2

output for second code: 第二个代码的输出:

2

Your code seems correct, are you sure that your id column in table is not empty. 您的代码似乎正确,确定表中的id列不为空。

If it is empty/blank it will be echoing something that you cannot recognize, to investiage you may put a counter and see if the effect is still same. 如果为空/空白,它将回显您无法识别的内容,以进行调查,您可以放置​​一个计数器,看看效果是否仍然相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM