views:

68

answers:

3
$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.

+6  A: 

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

munch
+2  A: 

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

Sarfraz
+3  A: 

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

Crayon Violent