[英]Return multiple count rows number in mysql
I have a two table rating and rate_table 我有两个表rating和rate_table
on rating table I have 在评分表上我有
ratingID, ratingname, userID.
1 RateA admin
2 RateB Admin
3 RateC 0001
On rate_table I have 在rate_table上,我有
ratingID come userID
1 xxxx 0001
2 xxxxx 0001
2 xxxxx 0001
3 xxxx 0001
2 xxxxx 0001
1 xxxxx 0001
I'm expecting a result like this but it seems. 我期待这样的结果,但看来。 not to work. 不上班。
RateA 2
RateB. 3
RateC 1
This is what I have tried: 这是我尝试过的:
<?php public function rating() {
$this -> jpt_connect();
$userID= $this ->users_info('userID');
$rating_ar = array();
$sql =mysql_query("SELECT
rt.ratingname,
COUNT(follows.userID) as id
FROM rating as rt
LEFT JOIN rate_table as tr
ON. (tr.userID = '$userID')
AND (tr.ratingID = rt.ratingID )
WHERE rt.userID ='admin'
OR rt.userID='$userID' ")
or die(mysql_error());
while($row= mysql_fetch_array($sql)) {
$rating_ar[] =$row;
}
return $rating_ar;
}
$j = new jkp();
$array =$j -> rating();
?>
How can I count the rate row in join with the rating name Please how can I access the var array ; 我如何计算与评级名称结合在一起的利率行,请问如何访问var数组; I will like send all the data that is coming from the db inside this array. 我想发送所有来自该数组内部db的数据。
I tried but nothing happen Thanks in advance 我尝试了但没有任何反应
Join ratings to rating objects and group by rating object: 将评级加入评级对象并按评级对象分组:
select o.name, count(1) votes
from votes v
join objects o ON o.id = v.object_id
group by o.id;
As seen on http://sqlfiddle.com/#!7/c1ebb/1 如http://sqlfiddle.com/#!7/c1ebb/1所示
I've renamed the tables, because I didn't get yours: 我已将表重命名,因为我没有得到您的表:
OBJECTS ( id, name )
VOTES ( object_id )
(only the relevant columns) (仅相关列)
edit Or maybe I didn't understand the problem at all. 编辑也许我根本不了解问题。 Follows? 跟随? The users are relevant? 用户相关吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.