运行以下内容时,我在标题中收到错误消息:
$year = date('Y');
$month = date('n');
$day = date('j') - 3;
$week = date('W') - 1;
$select = "SELECT IF( station_name = '', 'Unknown', station_name ) station_name, station_name as db_name, sum(case when year(print_date) = $year then print_pages end) as yearpages, sum(case when (month(print_date) = $month and year(print_date) = $year) then print_pages end) as monthpages, sum(case when (day(print_date) = $day and year(print_date) = $year and month(print_date) = $month) then print_pages end) as daypages, sum(case when (week(print_date) = $week AND year(print_date) = $year AND month(print_date) = $month) then print_pages end) as weekpages
FROM `file_prints`
GROUP BY station_name;";
$rows = $_userTable->getAdapter()->fetchAll($select);
foreach($rows as $key => $row)
{
$oModelStation = new Application_Model_PrintStation();
$fPrintsModel = new Application_Model_FilePrints();
$station = $oModelStation->fetchRow($oModelStation->select()->where('name = ?', $row['station_name']));
$row['weekpages'] = $fPrintsModel->fetchRow($fPrintsModel
->select(array('sum(print_pages) as weekpages'))
->where('station_name = ?', $row['station_name']));
->where('year(print_date) = ?', $year)
->where('week(print_date) = ?', $week));
echo $row['weekpages'];
错误追溯到最后一行是这个示例代码(echo $ row [' weekpages'])。我通过初始$ select SQL查询的回声测试了结果,看起来很令人满意,我已经尝试删除fetchRow执行中的各种where条件,看看是否有一个条件是责备但我继续得到相同的错误消息。
此外,当我使用此代码执行var_dump($ row)时,我看到,weekpages的键指向Zend对象,而daypages,monthpages和yearpages的所有其他键指向包含数值的字符串。
答案 0 :(得分:0)
错误消息告诉您问题所在。 fetchRow()返回一个Zend_Db_Table_Row对象,然后将其存储在索引'weekpages'中的数组中。我不确定您打算如何处理检索到的行中的数据,但您可以尝试将行对象转换为带有 - > toArray()的数组,或者访问行对象的各个字段,如下所示:
echo $row['weekpages']->weekpages;
假设您打算使用$ row ['weekpages']来保存行对象,尽管您选择索引的字符串会让我觉得可能不是这样。
为了进一步说明,$ row ['weekpages']的值是行对象,您在查询中使用别名的列也称为“weekpages”。