开发者

Retrieving results for query from MySQL using PHP

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜