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

search for in the

mysqli_result::fetch_all> <mysqli_result->current_field
Last updated: Fri, 14 Nov 2008

view this page in

mysqli_data_seek

result->data_seek

(PHP 5)

mysqli_data_seek -- result->data_seekAjusta o ponteiro do resultado para uma linha arbritaria no conjunto de resutados

Descrição

Estilo de procedimento:

bool mysqli_data_seek ( object $result , int $offset )

Estilo orientado a objetos (metodo):

result
bool data_seek ( int $offset )

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).

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().

Valores de retorno

Retorna TRUE em caso de sucesso ou FALSE em falhas.

Exemplo

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

Os exemplos acima devem produzir a seguinte saída:

City: Benin City  Countrycode: NGA


add a note add a note User Contributed Notes
mysqli_data_seek
kaisellgren at gmail dot com
09-Sep-2008 12:07
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.
 
}

?>

mysqli_result::fetch_all> <mysqli_result->current_field
Last updated: Fri, 14 Nov 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites