// generate and execute a query
$query = "SELECT DISTINCT * FROM birthdays ORDER BY fname";
$result= pg_query($connection, $query) or die("Error in query:$query. " .pg_last_error($connection));
// get the number of rows in the resultset
// this is PG-specific
$rows = pg_num_rows($result);
// if records present
if ($rows > 0)
{
// iterate through resultset
for ($i=0; $i<$rows; $i++)
{
$row = pg_fetch_object($result, $i);
?>
<li><?php echo $row->fname; ?> ||
<?php echo $row->lname; ?></li>