pg_result_seek

(PHP 4 >= 4.3.0, PHP 5)

pg_result_seek -- Set internal row offset in result resource

Описание

bool pg_result_seek ( resource result, int offset )

pg_result_seek() sets the internal row offset in a result resource.

Список параметров

result

PostgreSQL query result resource, returned by pg_query(), pg_query_params() or pg_execute() (among others).

offset

Row to move the internal offset to in the result resource. Rows are numbered starting from zero.

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Примеры

Пример 1. pg_result_seek() example

<?php

// Connect to the database
$conn = pg_pconnect("dbname=publisher");

// Execute a query
$result = pg_query($conn, "SELECT author, email FROM authors");

// Seek to the 3rd row (assuming there are 3 rows)
pg_result_seek($result, 2);

// Fetch the 3rd row
$row = pg_fetch_row($result);
 
?>



pg_result_seek
duke at spacebox dot net
09-Dec-2005 02:20
Unfortunately you're limited to a loop with a counter - all the pg_fetch functions increment the row counter *before* fetching a row, so something like

while ($row = pg_fetch_assoc($result)) {...}

is no longer possible after seeking or after fetching one or more results.  IMHO, the while loop is much better to look at than a for loop.

It'd be nice if there were a function to reset the current row to -1.  Perhaps the offset argument to the seek function could be optional; if left out the offset is set to -1.

bool pg_result_seek ( resource result[, int offset] )
andrew-php dot net at andrew dot net dot au
17-Sep-2004 08:01
Ah, this is a handy feature for resetting the record index, for example, if you're used pg_fetch_{row,array,assoc} to iterate over the result set, and you want to do it again later on, without reexecuting your query. Something like:

<?php pg_result_seek($result, 0); ?>

will allow you to iterate over the result set all over again...

<pg_result_errorpg_result_status>
 Last updated: Tue, 15 Nov 2005