[英]Retrieving results for query from MySQL using PHP
I want to query a MySQL database. 我想查询一个MySQL数据库。 I have the following.
我有以下几点。
$name
keeps changing in a loop. $name
不断循环变化。 ( $query
is a sample query here) (
$query
是此处的示例查询)
$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 #
. 与
echo "$result<br/>"
它只显示类似Resource id #
。 Nothing from $row
is printed. $row
没有任何内容。 The MySQL connection is fine. MySQL连接很好。 If I run the query without PHP, it works fine.
如果我在没有PHP的情况下运行查询,则效果很好。 What might be wrong?
可能是什么问题?
一切都是正确的,直到像循环中那样使用mysql_fetch_array()或mysql_fetch_assoc()之类的函数,您才能从$ result中获得任何收益。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.