对于特定查询
SELECT MAX(theCount), day
FROM (SELECT FK_Hour, day As day, Count(FK_Hour) As theCount
FROM (Select slottime.FK_Hour, time.day
From slottime INNER JOIN time ON slottime.FK_Hour = time.Hour )
As C GROUP By FK_Hour
)
AS counts GROUP By day
数据库返回
但是在运行php代码时
$timequery = array();
try {
$sth = $dbh->prepare("SELECT MAX(theCount), day
FROM (SELECT FK_Hour, day As day, Count(FK_Hour) As theCount
FROM (Select slottime.FK_Hour, time.day
From slottime INNER JOIN time ON slottime.FK_Hour = time.Hour )
As C GROUP By FK_Hour
)
AS counts GROUP By day
");
$sth->execute();
while ($timequery = $sth->fetch(PDO::FETCH_ASSOC)) {
$timequery[] = $results;
}
echo("trying ");
print_r($timequery);
echo(" tried");
}
输出仅为
尝试尝试
答案 0 :(得分:1)
$结果似乎未初始化...更改代码如下所示
while ($results = $sth->fetch(PDO::FETCH_ASSOC))