Reputation: 2443
a query :
$query=mysql_query(SELECT content_id, COUNT(*) FROM votingapi_vote WHERE value_type = option AND value = 1 GROUP BY content_id)
if i assign it to $result
.
while ($obj = db_fetch_object ($result)) {
$output .= $obj->content_id.'<br>' . $obj->count;
}
how to output the count number? after the $obj->content_id
. there is no number printed. thank you.
Upvotes: 1
Views: 527
Reputation: 2568
Try adding: $query=mysql_query(SELECT content_id, COUNT(*) *as the_count* FROM votingapi_vote WHERE value_type = option AND value = 1 GROUP BY content_id)
And then count should be in $obj->the_count
Upvotes: 1
Reputation: 238078
Give the count an alias, like:
SELECT content_id, COUNT(*) as the_count FROM ...
Then you can refer to it by that name:
$output .= $obj->content_id.'<br>' . $obj->the_count;
Upvotes: 3
Reputation: 49533
You need an alias for your column COUNT(*)
(i.e. rename the column) :
SELECT content_id, COUNT(*) as count FROM [...]
Then use the variable :
$obj->count
Upvotes: 3
Reputation: 28906
$query=mysql_query(SELECT content_id, COUNT(*) as count FROM votingapi_vote WHERE value_type = option AND value = 1 GROUP BY content_id)
Upvotes: 2