mysql_field_seek

(PHP 4, PHP 5)

mysql_field_seek将结果指针设置为指定的字段偏移量

警告

本扩展自 PHP 5.5.0 起已废弃,并在自 PHP 7.0.0 开始被移除。应使用 MySQLiPDO_MySQL 扩展来替换之。参见 MySQL:选择 API 指南来获取更多信息。用以替代本函数的有:

说明

mysql_field_seek(resource $result, int $field_offset): bool

定位到指定字段偏移量。如果下次调用 mysql_fetch_field() 不包含字段偏移量,则会返回 mysql_field_seek() 中指定字段的偏移量。

参数

result

resource 型的结果集。此结果集来自对 mysql_query() 的调用。

field_offset

数值型字段偏移量。 field_offset0 开始。如果 field_offset 不存在,则会发出一个 E_WARNING 级别的错误

返回值

成功时返回 true, 或者在失败时返回 false

参见

add a note add a note

User Contributed Notes 4 notes

up
3
adrien dot gibrat at gmail dot com
16 years ago
Not dumb at all!!

It means that "mysql_field_seek" and "mysql_data_seek" are moving the same cursor... through the rows and columns of the result resource.

Also means that the cursor goes to a new row when it reach a final field(aka column), by exemple while looping with "mysql_fetch_field".

Calling "mysql_fetch_object", "mysql_fetch_array", "mysql_fetch_assoc"
and "mysql_fetch_row" seems to place the cursor at the end of the line.

So calling "mysql_fetch_field" without a field index, just after that, will return false.
up
1
chris at igwsolutions dot com
16 years ago
I spent a good deal of time trying to get the example to work, but the example does not work.
To do what the exaple is trying to do, you would need to use mysql_data_seek

assume we have table named testing which contains
id      name
1       Hassan
2       Jack
3       Rose
---------------

Here is an expample that will do the above example.

Since I am more comfortable in a OOP setting, I used mysql_fetch_object

<?php
   
require("myConnenctionFile.php");
   
   
$sql="SELECT  * from testing";
   
$result=mysql_query($sql);

   
$row = mysql_fetch_object($result);
    echo
$row->id . ' ' . $row->name; // Output is (1      Hassan)
   
mysql_data_seek($result,2);
   
$row = mysql_fetch_object($result);
    echo
$row->id . ' ' . $row->name; // Output is (3      Rose)
   
echo "<BR><BR>";
?>
up
0
poulpillusion at free dot fr
17 years ago
A dumb comment... but it may save people some time :
mysql_field_seek != mysql_data_seek

In order to fetch again the results of a resource result from the beginning, you will use mysql_data_seek(id, 0)
up
-4
Hassan Kazem
16 years ago
an example of this function
assume we have table1 which contains
ID      Name
1       Hassan
2       Jack
3       Rose
---------------
<?php
mysql_connect
("sql.server.com", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$sql="SELECT  * from table1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
echo
$row['ID'] . ' ' . $row['Name']; // Output is (1      Hassan)
mysql_field_seek($result,2);
echo
$row['ID'] . ' ' . $row['Name']; // Output is (3      Rose)
?>
---------------
// You can see that the seek command forwarded the pointer one step and skipped row number 2
To Top