mysqli_result::data_seek

mysqli_data_seek

(PHP 5, PHP 7)

mysqli_result::data_seek -- mysqli_data_seekAjusta o ponteiro do resultado para uma linha arbritaria no conjunto de resutados

Descrição

Estilo orientado a objetos (metodo):

mysqli_result::data_seek ( int $offset ) : bool

Estilo de procedimento:

mysqli_data_seek ( mysqli_result $result , int $offset ) : bool

A função mysqli_data_seek() move para um resultado arbritario especificado por offset no conjunto de resultados especificado por result. O parâmetro offset deve estar entre zero e o número total de linhas menos uma (0..mysqli_num_rows() - 1).

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Notas

Nota:

Esta função só pode ser usadas para consultas não guardadas em buffer guardadas com o uso de mysqli_store_result() ou mysqli_query().

Exemplos

Exemplo #1 Estilo orientado a objeto

<?php
/* Open a connection */
$mysqli = new mysqli("localhost""my_user""my_password""world");

/* check connection */ 
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

$query "SELECT Name, CountryCode FROM City ORDER BY Name";
if (
$result $mysqli->query$query)) {

    
/* seek to row no. 400 */
    
$result->data_seek(399);

    
/* fetch row */
    
$row $result->fetch_row();

    
printf ("City: %s  Countrycode: %s\n"$row[0], $row[1]);
        
    
/* free result set*/
    
$result->close();
}

/* close connection */
$mysqli->close();
?>

Exemplo #2 Estilo de procedimento

<?php
/* Open a connection */
$link mysqli_connect("localhost""my_user""my_password""world");

/* check connection */ 
if (!$link) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

$query "SELECT Name, CountryCode FROM City ORDER BY Name";

if (
$result mysqli_query($link$query)) {

    
/* seek to row no. 400 */
    
mysqli_data_seek($result399);

    
/* fetch row */
    
$row mysqli_fetch_row($result);

    
printf ("City: %s  Countrycode: %s\n"$row[0], $row[1]);
        
    
/* free result set*/
    
mysqli_free_result($result);
}

/* close connection */
mysqli_close($link);
?>

O exemplo acima irá imprimir:

City: Benin City  Countrycode: NGA

Veja Também

add a note add a note

User Contributed Notes 1 note

up
24
kaisellgren at gmail dot com
15 years ago
This is useful function when you try to loop through the resultset numerous times.

For example:

<?php

$result
= mysqli_query($connection_id,$query);

while (
$row = mysqli_fetch_assoc($result))
{
 
// Looping through the resultset.
}

// Now if you need to loop through it again, you would first call the seek function:
mysqli_data_seek($result,0);

while (
$row = mysqli_fetch_assoc($result))
{
 
// Looping through the resultset again.
}

?>
To Top