/    Sign up×
Community /Pin to ProfileBookmark

restarting a sql result query from the beginning

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:

[code=php]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
}[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarMar 31.2008 — for mysql it's called [url=http://php.net/mysql_data_seek]mysql_data_seek()[/url] since your using pg though you'll need either [url=http://php.net/pg_lo_seek]pg_lo_seek()[/url] or [url=http://php.net/pg_result_seek]pg_result_seek()[/url] unless I'm mistaken.
Copy linkTweet thisAlerts:
@ss1289authorMar 31.2008 — awesome, pg_result_seek() works perfectly. Thanks
×

Success!

Help @ss1289 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...