Tom
Tom

Reputation: 541

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.

Upvotes: 0

Views: 531

Answers (3)

CrayonViolent
CrayonViolent

Reputation: 32532

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

Upvotes: 3

Sarfraz
Sarfraz

Reputation: 382646

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

Upvotes: 2

munch
munch

Reputation: 6321

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

Upvotes: 6

Related Questions