Function name: mysql_data_seek()
Applicable version: PHP 4, PHP 5, PHP 7
Function description: the mysql_data_seek() function moves the pointer in the result set to the specified line number.
Syntax: bool mysql_data_seek ( resource $result , int $row_number )
parameter:
Return value: Return true on success, and false on failure.
Example:
// 假设已连接到MySQL 数据库并选择了数据库// 执行查询$query = mysql_query("SELECT * FROM users"); // 检查查询是否成功if($query) { // 获取结果集中的总行数$total_rows = mysql_num_rows($query); // 将指针移动到第3行mysql_data_seek($query, 2); // 循环输出从第3行开始的结果集while($row = mysql_fetch_assoc($query)) { echo $row['username'] . "<br>"; } } else { echo "查询失败"; }
In the example above, we first execute a query and save the result into the $query
variable. Then, we use the mysql_data_seek()
function to move the pointer in the result set to line 3 (line number is 2, because the line number counts from 0). Next, we use the mysql_fetch_assoc()
function to loop out the username of each row in the result set starting from line 3. Note that we checked the results of the query before the loop to ensure the query is successful.