如何计算某个数据库表中的列+更多并在网站上显示(使用php)

I need my visitors on homepage to see how many active user we have. I need to include this with php. (need the code)

in mysql database user is marked with 0 (inactive) and 1 (active).

How can I count/read out the outcome, means all active users, of the database(database_name) - table(user_registration) - colums(each_one) - count(status)? How to publish this on my website?

Would prefer to this in php cause i'm not so used to js and query.

A simple methode/explanation would be very nice.

Thank you.

(need the code) first this is not a script writing service. Come up with some try and we will try giving a solution.

Basic necessity for your required active user count is to have a status (or name it something) column in your user table.

Then, while a user logs in change the status from 0 to 1 while logs out change it from 1 to 0

by doing so you could easily query it to display the active user.

select column,column from table where status = 1  
    //(i.e)
select id,userName from users where status = 1

Try using ajax if you want to display it like on-line users displayed in fb

In our implementation, I created a separate DB table active_users, wrote a php function to write user_id and timestamp to this table. This function is called via ajax from your page, bind it to whatever user action you see fit (in our case it is a search). Write another php function that queries the said tables and retrieves users with time difference between the timestamp and now less than specific value (in our case 5 min). call this function from your page via ajax either in specific time intervals (heartbeat) or user action again - mouse move etc. Display results of this call somewhere (in our case "Active Users" div)

this is what i have. it works good, but it just shows the amount of lines within.

How can i count all numbers in 'status' within those lines?

 <?php
    $con = mysql_connect($dbHost, $dbUser, $dbPass );
    mysql_select_db($dbName, $con);
    $res = mysql_query('SELECT Count(*) FROM ' . 'user_registration', $con);
    if ($row = mysql_fetch_array($res, MYSQL_NUM))
    {
       $users = trim($row[0]);
    }
    else
    {
       $users = 'Error';
    }
    ?>

to Show result on website:

<?= $users ?>