How to reuse the result of a sql query in PHP?
I would like to do different operations on data returned from one sql query, something like this:
$sql = "SELECT * FROM mandant";
$res = pg_query($_db,$sql);
while ($mandant_list = pg_fetch_object($res))
{
# do stuff
}
while ($mandant = pg_fetch_object($res))
{
# do other stuff
}
But it doesn't work. The first loop receives data, the second does not.
Is it possible to reuse the result returned from a query without rerunning it? If not, why not? What happens to the $ res variable?
+2
source to share
2 answers