douyoupingji7238 2014-02-11 17:57
浏览 85
已采纳

简单的MySQL WHILE循环没有运行

I'm trying to run a while loop from a MySQL query (which I've done a ton of times) and I can't get it to run for some reason. If I run the code below, I get 'test' echoed out but not 'test2' even though there are entries in the database that match the criteria in my SQL query. I guess I'm just trying to see if I'm overlooking something in the syntax?

I have the database connect files included on the page with 'require' statements so the page wouldn't even run if it was a mistake when connecting to the database.

Any ideas? I'm sorry if this is basic, it's just been driving me crazy this morning. Thank you for your help!

$sql_all = "SELECT * FROM wp_posts WHERE post_type = 'post' AND post_status != 'trash' AND post_status != 'auto-draft'";
$result_all = $mysqli->query($sql_all);

echo "test";

while($row_all == mysqli_fetch_array($result_all)){
    echo "test2";    
}
  • 写回答

1条回答 默认 最新

  • dongzhong5573 2014-02-11 18:00
    关注

    Take out the second equal sign in your while loop.

    while($row_all = mysqli_fetch_array($result_all)){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件