简体   繁体   English

MySQL while循环仅循环一次

[英]MySQL while loop only loops once

I have a database activities that stores activities information such as attendees, event description, event time, etc. 我有一个数据库activities ,用于存储活动信息,例如与会者,事件描述,事件时间等。

I call a while statement to print out the data, however the while loops is only looping once: 我调用while语句以打印出数据,但是while循环仅循环一次:

$result = mysqli_query($conn, "SELECT * FROM `activities` ORDER BY `date`");
while($act = mysqli_fetch_array($result)){ 
   //do some stuff
}

I did a var_dump of $result , and this is printed out: 我做了var_dump $result ,这是打印出来的:

object(mysqli_result)#3 (5) { ["current_field"]=> int(0) ["field_count"]=> int(11) ["lengths"]=> NULL ["num_rows"]=> int(26) ["type"]=> int(0) }

I have no idea what I'm doing wrong, can someone help? 我不知道我在做什么错,有人可以帮忙吗? thanks! 谢谢!

As per comments on the question. 根据对这个问题的评论。 Overwriting $result was the cause of this problem. 覆盖$ result是此问题的原因。

This is supposed to work. 这应该工作。

$result = mysqli_query($conn, "SELECT * FROM `activities` ORDER BY `activities`.`date`");

while($act = mysqli_fetch_array($result)){ 
   //do some stuff
}

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

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