Yet even simpler example:
$query = "SELECT * FROM atable";
$result = pg_query($query);
if (pg_num_rows($result)>0) {
while($row=pg_fetch_object($result) {
echo $row->first_column;
echo $row->second_column;
....
echo $row->last_column;
}
}
else {
echo "The query did not return any data!";
}