PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_data_seek() Function in PHP


Tutorials »Php »

Topic

What is mysql_data_seek function in PHP?
How does mysql_data_seek() works?




Explanation

The mysql_data_seek() function moves internal result pointer.

Syntax

bool mysql_data_seek ( resource result_identifier, int row_number)

Returns TRUE on success or FALSE on failure.

mysql_data_seek() is used to move the internal pointer of resultset returned by mysql_query() to a specific row.

mysql_data_seek() allows you to randomly access the results of a query by seeking (or moving) the internal record pointer of result set to the specified position.The offset starts from '0', if you specify offset as '5', pointer will be moved to fifth row of the result set.Subsequent calls to mysql_fetch_row() will retrieve rows starting from fifth position.

Example:


<?php

// Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

$db=mysql_select_db("My_database",$link);

// retrieve the mysql character encoding
$data = mysql_query('SELECT * FROM My_table',$link);

// attempt to seek to a specified position
if (!mysql_data_seek($data, 10))
echo 'Seek to record 10 failed!';
else
print_r(mysql_fetch_row($data));

mysql_close($link) ;
?>



Here internal record pointer of result $data is moved to 10th record using function mysql_data_seek($data, 10). Subsequent calls to mysql_fetch_row() will retrieve rows starting from 10th record.

See also: mysql_query() and mysql_num_rows()





Other Links

web hosting