I want to query a MySQL datab开发者_JAVA百科ase. I have the following. $name
keeps changing in a loop. ($query
is a sample query here)
$query = "SELECT id FROM table1 WHERE name='$name';";
$result = mysql_query($query) or die(mysql_error());
echo "$result<br/>";
While ($row = mysql_fetch_array($result)) {
echo $row["id"] . " - " . $row["name"];
}
with the echo "$result<br/>"
it just prints something like Resource id #
. Nothing from $row
is printed. The MySQL connection is fine. If I run the query without PHP, it works fine. What might be wrong?
Everything is correct, you'll get nothing from $result until you use some function like mysql_fetch_array() or mysql_fetch_assoc() like you do in your loop.
精彩评论