Reputation: 1990
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
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