开发者

While loop doesn't work

$r = mysql_query ( "SELECT guid FROM characters" );
if (mysql_num_rows($r) != 0) {
    while ( $row == mysql_fetch_array ( $r ) ) {
        $cap = rand ( 0, $char );
        if ($row ['guid'] != $cap) {
            $captain = rand ( 0, $char );
        } 
    }
} else {
    $captain = rand ( 0, $char );
}

This code should return m开发者_C百科e the guid of character, which is not recorded in the characters table yet. The first part with if works, but the loop doesn't work at all, I tried to add print "text"; in it but it didn't return nothing.


Try:

while ( $row = mysql_fetch_array ( $r ) )

You want to set $row equal to the result of mysql_fetch_array, not compare it against the result


You are using == in your while loop. You should be using = (the assignment operator). Also just a note, you should use mysql_fetch_assoc instead of mysql_fetch_array. mysql_fetch_array returns 2x the info (both numeric and associative versions of the data).


You are using == (comparison) instead of = (equality) in while loop.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜