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

search for in the

mssql_execute> <mssql_connect
Last updated: Fri, 14 Aug 2009

view this page in

mssql_data_seek

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

mssql_data_seekDéplace le pointeur interne de ligne

Description

bool mssql_data_seek ( resource $result_identifier , int $row_number )

mssql_data_seek() déplace le pointeur interne de ligne, dans le résultat result_identifier , jusqu'à la ligne row_number , la première étant numérotée 0. Le prochain appel à mssql_fetch_row() retournera cette ligne.

Liste de paramètres

result_identifier

La ressource de résultat à évaluer.

row_number

Le numéro de la ligne désiré pour le nouveau pointeur de résultat.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Exemples

Exemple #1 Exemple avec mssql_data_seek()

<?php
// Connexion à MSSQL
$link mssql_connect('MANGO\SQLEXPRESS''sa''phpfi');
mssql_select_db('php'$link);

// Sélection de tout le monde
$result mssql_query('SELECT [name], [age] FROM [persons] WHERE [age] >= 13');

if(!
$result)
{
    die(
'La requête a échoué.');
}

// Sélection d'un étudiant sur quatre, dans les résultats
for($i mssql_num_rows($result) - 1$i 4$i++)
{
    if(!
mssql_data_seek($result$i))
    {
        continue;
    }
    
    
// Lecture d'une ligne...
}

// Libération du résultat
mssql_free_result($result);
?>



add a note add a note User Contributed Notes
mssql_data_seek
phpcomments at hltools dot com
20-Jul-2005 11: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");
}
?>

mssql_execute> <mssql_connect
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites