downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

mssql_execute> <mssql_connect
[edit] Last updated: Fri, 17 May 2013

view this page in

mssql_data_seek

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

mssql_data_seekDesplaza el apuntador interno de fila

Descripción

bool mssql_data_seek ( resource $result_identifier , int $row_number )

mssql_data_seek() desplaza el apuntador interno de fila dentro del resultado de MS SQL (result_identifier) hasta apuntar al número de fila row_number, siendo la primera fila la número 0. La siguiente llamada a mssql_fetch_row() devolverá esa fila.

Parámetros

result_identifier

El identificador del resultado que está siendo evaluado.

row_number

El número de fila al que se desea apuntar en el resultado.

Valores devueltos

Devuelve TRUE en caso de éxito o FALSE en caso de error.

Ejemplos

Ejemplo #1 mssql_data_seek() example

<?php
// Conectar a MSSQL y seleccionar la base de datos
$link mssql_connect('MANGO\SQLEXPRESS''sa''phpfi');
mssql_select_db('php'$link);

// Seleccionar a todo el mundo
$result mssql_query('SELECT [name], [age] FROM [persons] WHERE [age] >= 13');

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

// Seleccionar a cada 4º estudiante en los resultados
for ($i mssql_num_rows($result) - 1$i 4$i++) {
    if (!
mssql_data_seek($result$i)) {
        continue;
    }

    
// Leer la fila ...
}

// Liberar el resultado
mssql_free_result($result);
?>



add a note add a note User Contributed Notes mssql_data_seek - [1 notes]
up
-1
phpcomments at hltools dot com
7 years ago
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");
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites