简体   繁体   中英

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 me 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).

您在while循环中使用== (比较)而不是= (等于)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM