2015-01-03 64 views
2

所以我有这样的语句来抓取所有帖子MySQL存储功能和PHP

select id, title 
from posts 
where type = 'article' 

和我有一个存储函数计算总的意见,并返回结果

我知道我可以执行它像

select totalView(id) 

,但我怎么能合并这两个查询与每个总视图退回所有帖子发布

可能类似于

select id, title, totalView(id) as total 
from posts 
where type = 'article' 

谢谢。

+2

请出示TotalView的功能 – Aris

+1

你给** **是回答你问的问题的例子。 – symcbean

回答

0
select count(*) as total, id, title from posts where type = 'article' 

编辑:将计算$ ID的所有行

select count(*) as total, id, title from posts where type = 'article' AND id = $id; 
+0

感谢您的评论,但totalView是一个存储函数,它将文章的id作为参数并返回总体视图。 – Roy5