Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Microsoft SQL Server Functions : mssql_data_seek

mssql_data_seek

Moves internal row pointer (PHP 4, PHP 5, PECL odbtp:1.1.1-1.1.4)
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.

Parameters

result_identifier

The result resource that is being evaluated.

row_number

The desired row number of the new result pointer.

Return Values

Returns TRUE on success or FALSE on failure.

Examples ( Source code ) » mssql_data_seek

<?php
// Connect to MSSQL
mssql_connect('navioo\SQLEXPRESS''sa''phpfepsilon); 
mssql_select_db('
php', $link);

// Select all people
$result = mssql_query('
SELECT [name], [ageFROM [personsWHERE [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);
?>

Code Examples / Notes » mssql_data_seek

phpcomments

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");
}
?>


Change Language


Follow Navioo On Twitter
mssql_bind
mssql_close
mssql_connect
mssql_data_seek
mssql_execute
mssql_fetch_array
mssql_fetch_assoc
mssql_fetch_batch
mssql_fetch_field
mssql_fetch_object
mssql_fetch_row
mssql_field_length
mssql_field_name
mssql_field_seek
mssql_field_type
mssql_free_result
mssql_free_statement
mssql_get_last_message
mssql_guid_string
mssql_init
mssql_min_error_severity
mssql_min_message_severity
mssql_next_result
mssql_num_fields
mssql_num_rows
mssql_pconnect
mssql_query
mssql_result
mssql_rows_affected
mssql_select_db
eXTReMe Tracker