Looks like you are unfamiliar with more than just arrays 🙂
$data = pg_fetch_row ($result);
pg_fetch_row() requires a rownumber to indicate which of the resultset rows you want to fetch.
Furthermore, your method will fail if there are no results to fetch, you should check wether there are any results to fetch before you fetch them
Using pg_fetch_assoc() rather than pg_fetch_row(), will give you an associative array, which means you can use column names instead of fieldnumbers (much easier to work with)
//assume database connectivity
$sql = "some SQL statement"
if (!$result = pg_query ($dbconn, $sql))
{
echo 'query failed, print psql error here';
exit;
}
else
{
// Did the query return any results?
$iNumberOfResults = pg_num_rows($result);
$aRows[]=array();
if ($iNumberOfResults>0)
{
// yes there were results, fetch them
for ($iT = 0; $iT< $iNumberOfResults; $iT++)
{
$aRows[] = pg_fetch_assoc($result, $iT) ;
}
}
now you shoukd have an array $aRows:
echo 'Number of rows in array:'.count($aRows);
and you can access the data like this:
echo $aRows[$rownumber]['columnname'];