这是我的查询,其中我获得每周和总观看次数
select count(ms.test_public_id) as total_views, ms1.recent_views from test_stats ms
join (select count(test_stats.test_public_id) as recent_views from test_stats
where test_stats.test_public_id = '$tourid'
and test_stats.updated_on > DATE_SUB(CURDATE(), INTERVAL 7 DAY)) ms1
where ms.test_public_id ='$tourid'
我试图在zend中实现输出就像这样
$cols = array ('count(ms.test_public_id) as total_views', 'ms1.recent_views', 'count(test_stats.test_public_id) as recent_views' );
$select = $db ->select ()
->from ( 'test', $cols )
->join ( 'user', 'user.user_id = test.user_id', array () )
->join ( 'test_stats', 'test_stats.test_public_id =test.test_public_id', array ())
->where ( 'test_stats.test_public_id = ?', '$testId' )
->where ( 'test_stats.updated_on > DATE_SUB(CURDATE(), INTERVAL 7 DAY)' )
->where ( 'ms.test_public_id = ?', '$testId' )
->group ( 'test_stats.test_public_id' )
->order ( 'title' );
$result = $db->fetchAll ( $select );
请纠正我在哪里做错了..........
答案 0 :(得分:0)
->join ( 'user', 'user.user_id = test.user_id', array () );
为什么空数组呢?并且标题在顺序中是不明显的...我认为....尝试 echo $ select = ....以查看执行的查询和比较用你想要的东西。
TRY
$cols = array ('count(ms.test_public_id) as total_views', 'ms1.recent_views', 'count(test_stats.test_public_id) as recent_views' );
echo $select = $db ->select ()
->from ( 'test', $cols )
->join ( 'user', 'user.user_id = test.user_id', array () )
->join ( 'test_stats', 'test_stats.test_public_id =test.test_public_id', array ())
->where ( 'test_stats.test_public_id = ?', '$testId' )
->where ( 'test_stats.updated_on > DATE_SUB(CURDATE(), INTERVAL 7 DAY)' )
->where ( 'ms.test_public_id = ?', '$testId' )
->group ( 'test_stats.test_public_id' )
->order ( 'test.title' );
$result = $db->fetchAll ( $select );