You are here: resetting pg_fetch_array « PHP « IT news, forums, messages
resetting pg_fetch_array

Posted by Dave O on 02/22/05 18:01

Hi all. I'm been trying the following code for the past day or so and I
can't seem to get around it. I'm issuing a query to pgsql and
iterating through the results twice in order to facilitate the
separation of shipment history.

Below is the simplest example I can come up with. The results only
display once, even though I'm not issuing any other db calls after the
1st iteration and the resouce id remains the same. Heck, even
pg_num_rows returns the same result twice, but the results just won't
display a second time.

I'm running this on freebsd 5.3 using pgsql v8 and php 4.3.10. Anybody
got any suggestions. TIA.

Dave

table looptest
rownum | rowstr
--------+--------
1 | aaaaaa
2 | bbbbbb
3 | cccccc
4 | dddddd

include ('connection.inc.php');
$sql = "SELECT rownum, rowstr FROM looptest";
$result = pg_query($conn, $sql);
$c=2;
$x=0;
echo "<pre>\n";
while ($x<$c)
{
echo pg_num_rows($result) . "->";
print_r($result);
echo "\n\n";
reset($result);
while($row = pg_fetch_array($result))
{
echo $row["rownum"] . " -> " . $row["rowstr"] . " \n";
}

echo "====================================\n";

$x++;

}

echo "</pre>\n";

----------------------------------
results
----------------------------------

4->Resource id #4

1 -> aaaaaa
2 -> bbbbbb
3 -> cccccc
4 -> dddddd
====================================
4->Resource id #4

====================================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация