douyoupingji7238 2014-02-11 09: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 10:00
    关注

    Take out the second equal sign in your while loop.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部