Close, but you need to add an incrementing counter to your while loop to make it loop, or use a for next loop.
For next style:
$rows=pg_numrows($sql_result);
for ($i=0;$i<$rows;$i++){
$row=pg_fetch_array($sql_result,$i);
do something here...
}
While loop with increment:
$count=0;
while ($row=pg_fetch_array($sql_result,$i)){
do something with $row here
$count++;
}