获取mysql资源字符串的第一行? [英] Getting the first row of the mysql resource string?

查看:210
本文介绍了获取mysql资源字符串的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题. 我需要数据库中的多个行,并且我需要执行某些任务的第一行,然后再次遍历所有列表以创建记录集.

Here is my problem. I need more than one row from the database, and i need the first row for certain task and then go through all the list again to create a record set.

$query = "SELECT * FROM mytable";
$result = mysql_query($query);

$firstrow = //extract first row from database
//add display some field from it


while($row = mysql_fetch_assoc($result)) {
   //display all of them
}

现在,如何仅提取第一行?

Now, how to extract just the first row?

推荐答案

使用mysql_fetch_assoc()不仅获取一行,还将结果集的内部指针移至下一行.要将结果资源重置为第一行,您需要使用mysql_data_seek().

Using mysql_fetch_assoc() not only fetches a row, it also moves the internal pointer of the result set to the next row. To reset the result resource to the first row, you need to use mysql_data_seek().

$query = "SELECT * FROM mytable";
$result = mysql_query($query);

$firstrow = mysql_fetch_assoc($result);

// reset the result resource
mysql_data_seek($result, 0);


while($row = mysql_fetch_assoc($result)) {
   //display all of them
}

这篇关于获取mysql资源字符串的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆