开发者

how to print the count number in mysql?

开发者 https://www.devze.com 2023-03-07 12:43 出处:网络
a query : $query=mysql_query(SELECT content_id, COUNT(*) FROM votingapi_vote WHERE value_type = optionAND value = 1 GROUP BY content_id)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消