Current Location: Home> Function Categories> mysql_data_seek

mysql_data_seek

Move the record pointer.
Name:mysql_data_seek
Category:Uncategorized
Programming Language:php
One-line Description:Move the pointer in the result set to the specified row number

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:

  • result: MySQL query result resource, obtained through the mysql_query() function.
  • row_number: The line number to which the pointer is to be moved, and the line number starts from 0.

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.

Similar Functions
Popular Articles