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_i开发者_如何学Pythond
. there is no number printed. thank you.
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
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;
$query=mysql_query(SELECT content_id, COUNT(*) as count FROM votingapi_vote WHERE value_type = option AND value = 1 GROUP BY content_id)
Change
COUNT(*) FROM
to
COUNT(*) as count FROM
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
精彩评论