我对从 MySQL 获取的数组 $row 有一些问题
我对从 MySQL 获取的数组有一些问题
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
mysql_fetch_row($result);
echo $row[0]; // doesn't work
echo $row[1]; // doesn't work
,但是这项工作
echo $row["FirstFieldName"] //OK
...
我应该如何更改以下代码才能使其工作?
for ( $i = 0; $i < count( $row ); $i++ )
{
echo $row[ $i ];
}
谢谢
I've some issues with an array fetched from MySQL
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
mysql_fetch_row($result);
echo $row[0]; // doesn't work
echo $row[1]; // doesn't work
but this work
echo $row["FirstFieldName"] //OK
...
how should I change the following code to make it work?
for ( $i = 0; $i < count( $row ); $i++ )
{
echo $row[ $i ];
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
进行以下更改。使用
mysql_fetch_array
代替mysql_fetch_row()
mysql_fetch_row()
从与指定结果标识符关联的结果中获取一行数据。该行作为数组返回。每个结果列都存储在一个数组偏移量中,从偏移量 0 开始。Do below changes. use
mysql_fetch_array
instead ofmysql_fetch_row()
mysql_fetch_row()
fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.尝试使用 mysql_fetch_array() 代替。
您应该研究的三个函数是:
mysql_fetch_row、
mysql_fetch_array 和
mysql_fetch_assoc
每个的做法都略有不同。
试试这样:
Try using mysql_fetch_array() instead.
The three functions you should look into are:
mysql_fetch_row,
mysql_fetch_array, and
mysql_fetch_assoc
Each does things a little differently.
Try it this way:
会起作用的
it will work
mysql_fetch_row
返回一行,因此为了能够使用它,您应该这样做:否则,正如 Mike 所说,您应该使用
mysql_fetch_array()
mysql_fetch_row
returns one row, so to be able to use it you should do :Otherwise, as Mike said you should use
mysql_fetch_array()
即....这将获取所有检索到的键/字段并对它们进行交互并将它们交给$s,然后可以将其放入html中..
ie.... this takes all the retrieved keys/fields and intereates them and hands them off to $s which can then be placed into html..