dongtuo5611
2014-03-12 14:07
浏览 87
已采纳

如何循环通过mysqli查询结果?

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

$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

图片转代码服务由CSDN问答提供 功能建议

你好我使用下面的代码来显示所有的查询结果,但它只给了我一个

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

此代码工作正常,给我2个结果,但当我使用

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

它只给我一个结果?

输出第一个代码:

  xk-1 xk-2 
   
 
 

输出 第二个代码:

  2 
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsljpwi494719 2014-03-12 14:12
    已采纳

    Your code seems correct, are you sure that your id column in table is not empty.

    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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题