mysql_field_seek
(PHP 4, PHP 5, PECL mysql:1.0)
mysql_field_seek — Устанавливает внутренний указатель поля на переданное смещение.
Описание
array mysql_field_seek
( resource $result
, int $field_offset
)
Перемещает указатель к колонке с переданным индексом. Если следующий вызов функции не содержит смещения, будет возвращено смещение, содержащееся в mysql_field_seek().
См. также mysql_fetch_field().
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MySQL Drivers and Plugins
- Оригинальное API MySQL
- mysql_affected_rows
- mysql_client_encoding
- mysql_close
- mysql_connect
- mysql_create_db
- mysql_data_seek
- mysql_db_name
- mysql_db_query
- mysql_drop_db
- mysql_errno
- mysql_error
- mysql_escape_string
- mysql_fetch_array
- mysql_fetch_assoc
- mysql_fetch_field
- mysql_fetch_lengths
- mysql_fetch_object
- mysql_fetch_row
- mysql_field_flags
- mysql_field_len
- mysql_field_name
- mysql_field_seek
- mysql_field_table
- mysql_field_type
- mysql_free_result
- mysql_get_client_info
- mysql_get_host_info
- mysql_get_proto_info
- mysql_get_server_info
- mysql_info
- mysql_insert_id
- mysql_list_dbs
- mysql_list_fields
- mysql_list_processes
- mysql_list_tables
- mysql_num_fields
- mysql_num_rows
- mysql_pconnect
- mysql_ping
- mysql_query
- mysql_real_escape_string
- mysql_result
- mysql_select_db
- mysql_set_charset
- mysql_stat
- mysql_tablename
- mysql_thread_id
- mysql_unbuffered_query
Коментарии
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)
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
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>";
?>
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.