cicakman
cicakman

Reputation: 1990

php mysql multiple result

My php code:

$sql = mysql_query("SELECT * FROM users WHERE user_id IN (1,3)");
    while($row = mysql_fetch_array($sql)) {
    echo $row['name'];
    }

It returns as last result set, which is from user_id = 3 and does not include the result of user_id = 1 but when i print_r($row) all the result is there, is there anything amiss?

Thanks

Upvotes: 1

Views: 1122

Answers (1)

Rajat Singhal
Rajat Singhal

Reputation: 11264

If you want to access elements of array by attribute names use this:

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
   printf("ID: %s  Name: %s", $row["id"], $row["name"]);
}

else just use numeric instead of associative keys

as

echo $row[0]

Upvotes: 3

Related Questions