这个是数据库写法,如果只需要hits的总和可以这样写,我是所有的都列出来了方便你学习这个是用来查询总的。SELECT( SELECT sum( hits ) FROM dr_1_book_extend WHERE cid = 104 ) as totalFROMdr_1_book AS aINNER JOIN dr_1_book_extend AS b ON b.cid = a.id WHEREb.cid = 104;
程序中你要写可以这样写查询汇总总数$total = \Phpcmf\Service::M()->db->query('SELECT ( SELECT sum( hits ) FROM dr_1_book_extend WHERE cid = 104 ) as total FROM dr_1_book AS a INNER JOIN dr_1_book_extend AS b ON b.cid = a.id WHERE b.cid = 104;')->getResultArray();这个是输出汇总的总数,这样就可以了,这两段代码就可以解决,104就是你那篇小说的id不是他下面的篇章的id,就是这个的id,代码都写好了,可以拿来直接用
程序中你要写可以这样写查询汇总总数$total = \Phpcmf\Service::M()->db->query('SELECT ( SELECT sum( hits ) FROM dr_1_book_extend WHERE cid = 104 ) as total FROM dr_1_book AS a INNER JOIN dr_1_book_extend AS b ON b.cid = a.id WHERE b.cid = 104;')->getResultArray();这个是输出汇总的总数,这样就可以了,这两段代码就可以解决,104就是你那篇小说的id不是他下面的篇章的id,就是这个的id,代码都写好了,可以拿来直接用
echo $total[0]['total'];