Mssql 函数
在线手册:中文 英文
PHP手册

mssql_data_seek

(PHP 4, PHP 5, PECL odbtp >= 1.1.1)

mssql_data_seekMoves internal row pointer

说明

bool mssql_data_seek ( resource $result_identifier , int $row_number )

mssql_data_seek() moves the internal row pointer of the MS SQL result associated with the specified result identifier to point to the specified row number, first row being number 0. The next call to mssql_fetch_row() would return that row.

参数

result_identifier

The result resource that is being evaluated.

row_number

The desired row number of the new result pointer.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE.

范例

Example #1 mssql_data_seek() example

<?php
// Connect to MSSQL and select the database
$link mssql_connect('MANGO\SQLEXPRESS''sa''phpfi');
mssql_select_db('php'$link);

// Select all people
$result mssql_query('SELECT [name], [age] FROM [persons] WHERE [age] >= 13');

if (!
$result) {
    die(
'Query failed.');
}

// Select every 4th student in the results
for ($i mssql_num_rows($result) - 1$i 4$i++) {
    if (!
mssql_data_seek($result$i)) {
        continue;
    }

    
// Fetch the row ...
}

// Free the query result
mssql_free_result($result);
?>


Mssql 函数
在线手册:中文 英文
PHP手册
PHP手册 - N: Moves internal row pointer

用户评论:

phpcomments at hltools dot com (20-Jul-2005 12:33)

mssql_data_seek will return false AND trigger a warning ('Bad row offset') if you specify a row outside the result set.
You'll need to check beforehand if the row you are trying to seek to exists. Or you can supress the error and look for the false result, depending on your needs.

To check beforehand (where $result is the result fo your query and $seek is the row number you want to seek to):
<?php
$rowcount
= mssql_num_rows($result);
if (
$seek >= $rowcount)
{
    print (
"Trying to seek outside result set!");
}
else
{
    if (!
mssql_data_seek($result, $seek))
    {
        print (
"Seek failed");
    }
    else
    {
        print (
"Seek complete");
    }
}
?>

To have a 'simpler' way of handling errors by supressing the warning:
<?php
if (!@mssql_data_seek($result, $seek))
{
    print (
"Seek failed");
}
else
{
    print (
"Seek complete");
}
?>