嘿伙计们,我有一个 postgres 数据库,我正在使用 php 连接并获取数据。我是php的新手。但无论如何我有这个作为我的查询
$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";
我有这个来返回被查询的数据:
// 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 />";
}
这会以这种格式返回我的数据
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
但是希望在表中包含这些数据,其中月份、开始时间、结束时间、分钟、不同的呼叫者、国家代码和国家是表中的列标题。我怎样才能做到这一点。