Click to See Complete Forum and Search --> : restarting a sql result query from the beginning


ss1289
03-31-2008, 12:05 PM
I want to loop through the results of a query twice. So since fetch_assoc has a counter that points to the next value after each pass in the loop I was wondering if there is a php sql function to restart the fetch_assoc counter to the beginning and do another loop with the same query results. I don't want to have to pull the same results using query() twice.

For example:
res = pg_query($query);
while($row = pg_fetch_assoc($res)){
//get info and do something
}

while($row = pg_fetch_assoc($res)){
//get info and do something different
}

scragar
03-31-2008, 12:08 PM
for mysql it's called mysql_data_seek() (http://php.net/mysql_data_seek) since your using pg though you'll need either pg_lo_seek() (http://php.net/pg_lo_seek) or pg_result_seek() (http://php.net/pg_result_seek) unless I'm mistaken.

ss1289
03-31-2008, 12:15 PM
awesome, pg_result_seek() works perfectly. Thanks