How to display counted value of database column using count function in php?

I have two tables (newassignment,bugstatus) I have made one query i.e
$query = "select assign_name,credit,(select count(bug_id) from bugstatus where client_userid=2 and assign_id=2 group by bug_status having bug_status=’Approved’),(select count(bug_status) from bugstatus where client_userid=2 and assign_id=2 group by bug_status having bug_status=’Pending’) from newassignment where client_userid=2";

this query is executed in mysql but I don’t understand how to display this sql output in php page. I am able to display first value i.e assign_name,credit value but can’t display counted value which is given subquery.

UPDATE: Seems I misread your question.

What you need to do is set a "column name" for the computed value, for example:

SELECT count(ColumnID) AS RowCount FROM TableName

The "AS RowCount " is the key to giving it a column name, this way you will be able to reference it much easier with in PHP, just like your other columns.

One Response to “How to display counted value of database column using count function in php?”

  1. Spiral Friends, Inc on November 11th, 2009 at 12:13 pm

    UPDATE: Seems I misread your question.

    What you need to do is set a "column name" for the computed value, for example:

    SELECT count(ColumnID) AS RowCount FROM TableName

    The "AS RowCount " is the key to giving it a column name, this way you will be able to reference it much easier with in PHP, just like your other columns.
    References :

Leave a Reply