开发者

What's the equivalent syntax of while($row = mysql_fetch_array($result)) for a "for loop"

开发者 https://www.devze.com 2023-04-07 04:23 出处:网络
I wanted to know if it was possible to write the following expression while($row = mysql_fetch_array($result))

I wanted to know if it was possible to write the following expression

while($row = mysql_fetch_array($result))

wit开发者_如何学运维h a "for loop" instead of a "while loop." So that the below code would print the same result.

while($row = mysql_fetch_array($result)){
    echo $row['name'];
}

EDIT: I use PDO I just thought this would be an expression more people have seen. And as far as the answers go, yeah I agree it would be pointless. I'm just having trouble understanding how the internal pointer increments.


It would be really pointless, but you could do:

for(;$row = mysql_fetch_array($result);) {
    echo $row['name'];
}

However, you should seriously consider using PDO.


for($row = NULL; $row = mysql_fetch_array($result);;) {
    echo $row['name'];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消