Hey guys i have a postgres database to which i am connecting and fetching data from using php. I am a newbie to php. But anyway i have this as my query
$sql = "SELECT to_char (a.CALLDATE,'yyyymm') as month,min(a.calldate) as start_time,max(a.calldate) as end_time,
ceil(SUM (a.CALLDURATION::integer) / 60) AS minutes,
COUNT (DISTINCT a.IDENTIFIANT) AS distinct_callers,
a.zoneiddest as country_code,b.country
FROM cdr_data a,COUNTRY_CODES b
WHERE a.CALLSUBCLASS = '002'
AND a.CALLCLASS = '008'
and a.zoneiddest::integer > 0
AND SUBSTR (a.CALLEDNUMBER, 1, 2) NOT IN
('77', '78', '75', '70', '71', '41', '31', '39', '76','79')
and not substr(a.zoneiddest , 1 ,3) in ('254','255','256','211','257','250','256')
and trim(a.zoneiddest) = trim(b.country_code)
GROUP BY to_char (a.CALLDATE,'yyyymm') ,a.zoneiddest,b.country
ORDER BY 1";
And i have this to return the data that is queried:
// iterate over result set
// print each row
while ($row = pg_fetch_array($result)) {
echo "Month: " . $row[0] . "<br />";
echo "Start Time: " . $row[1] . "<br />";
echo "End Time: " . $row[2] . "<br />";
echo "Minutes: " . $row[3] . "<br />";
echo "Distinct Callers: " . $row[4] . "<br />";
echo "Country Code: " . $row[5] . "<br />";
echo "Country: " . $row[6] . "<br />";
}
This returns my data in this format
Month: 201212
Start Time: 2012-12-28 15:51:04
End Time: 2012-12-28 15:51:04
Minutes: 0
Distinct Callers: 1
Country Code: 44
Country: United Kingdom of Great Britain and Northern Ireland
But would love to have this data in the table where month, start time, end time, minutes, distinct callers, country code and country are the column headers in the table. How can i achieve this.