I've selected all the records from a database for display, and am trying to form a loop so that it will display all records, but it's just displaying the same record 15 times (there are 15 rows in the database). I can't see where i've gone wrong! My code is below, if anyone can help I would be most grateful!

Thanks,

Jon.

**The Code**
$sql = "SELECT *
FROM contacts";

// Execute the query and put results in $result

$result = pg_exec($sql);

// Get the number of rows and put in $num

$num = pg_numrows($result);

// Start the table.

echo "<P><center>";
echo "<TABLE cellpadding=2 cellspacing=0 bgcolor=#050DA5>";

// Loop for as long as $i <= $num

while($i <= $num) {

echo "<tr><td bgcolor=#80FF80>";
echo pg_result($result,'$i','real_name');
echo "<br>";
echo pg_result($result,'$i','dob');
echo "</td><td bgcolor=#80FF80>";
echo pg_result($result,'$i','address1');
echo "<br>";
echo pg_result($result,'$i','address2');
echo "<br>";
echo pg_result($result,'$i','town');
echo "<br>";
echo pg_result($result,'$i','postcode');
echo "</td><td bgcolor=#80FF80>";
echo pg_result($result,'$i','email1');
echo "<br>";
echo pg_result($result,'$i','email2');
echo "</td><td bgcolor=#80FF80>";
echo pg_result($result,'$i','telhome');
echo "<br>";
echo pg_result($result,'$i','telmob');
echo "<br>";
echo pg_result($result,'$i','telpage');
echo "</td></tr>";

// increment to continue looping

$i++;

}

// Finish the table and page.

echo "</table></body></html>"

?>

**End**