mysql_field_seek
Sets the pointer in the result set to the specified field offset.
Function name: mysql_field_seek()
Applicable version: PHP 4, PHP 5, PHP 7
Usage: The mysql_field_seek() function moves the pointer in the result set to the specified field offset position. This allows random access to field values in the result set.
Syntax: bool mysql_field_seek ( resource $result , int $field_offset )
parameter:
Return value: Return TRUE when successful, and FALSE when failure.
Example:
// 连接到MySQL 数据库$link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('连接数据库失败: ' . mysql_error()); } // 选择数据库$db_selected = mysql_select_db('database_name', $link); if (!$db_selected) { die('选择数据库失败: ' . mysql_error()); } // 执行查询$query = 'SELECT * FROM table_name'; $result = mysql_query($query); if (!$result) { die('查询失败: ' . mysql_error()); } // 将结果集的指针移动到第二个字段if (mysql_field_seek($result, 1)) { // 获取该字段的值$field_value = mysql_fetch_field($result); echo '第二个字段的值为: ' . $field_value->name; } else { echo '移动指针失败'; } // 释放结果集mysql_free_result($result); // 关闭数据库连接mysql_close($link);
Notes: