警告:条件分配 [英] Warning: Assignment in condition
本文介绍了警告:条件分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一件事总是欺骗我,当检查我的php脚本的问题,我得到警告bool分配:条件分配,我得到他们很多。
例如:
One thing that has always bugged me is that when checking my php scripts for problems I get the warning "bool-assign : Assignment in condition" and I get them a lot. e.g.:
$guests = array();
$sql = "SELECT * FROM `guestlist`";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
$guests[] = $row['name'];
有不同的方法来获取多个或所有行到一个对象或数组?
Is there a different way to get multiple or all rows into an object or array? Or is there nothing wrong with this method?
推荐答案
尝试这样做:
$guests = array();
$sql = "SELECT * FROM `guestlist`";
$result = mysql_query($sql);
while(($row = mysql_fetch_assoc($result)) !== false)
$guests[] = $row['name'];
我相信php是警告,因为$ row = mysql_fetch_assoc($ result)不返回布尔值。
I believe php is warning because of the $row = mysql_fetch_assoc($result) not returning a boolean.
这篇关于警告:条件分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文