Warning: assignment in state

One thing that has always bothered me is that when I check my php scripts for problems, I get a "bool-assign: Assignment in condition" warning, and I get a lot of them. eg:.

$guests = array();
$sql = "SELECT * FROM `guestlist`";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
    $guests[] = $row['name'];

Is there any other way to get some or all of the rows in an object or array? Or is there nothing wrong with this method?

+3
source share
2 answers

try to do this instead:

$guests = array();
$sql = "SELECT * FROM `guestlist`";
$result = mysql_query($sql);
while(($row = mysql_fetch_assoc($result)) !== false)
    $guests[] = $row['name'];

I believe php warns because of $ row = mysql_fetch_assoc ($ result) not returning a boolean.

+13
source

, , , . :

if (something == something_else)

:

if (something = something_else)

, , . PHP - C, , :

while(($row = mysql_fetch_assoc($result)))

, , PHP .

+3

Source: https://habr.com/ru/post/1705919/


All Articles