i got the following MYSQL query...im very new to PHP
select count(online) from login_details where online='y';
this will result the total count of online users ....eg;10
How can i store it in PHP variable or print this value ????
Problem in PHP MYSql Query
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Problem in PHP MYSql Query
I would do something like:
select count(online) AS online_users from login_details where online='y';
The code is something like:
select count(online) AS online_users from login_details where online='y';
The code is something like:
Code: Select all
$result = $db->query("select count(online) AS online_users from login_details where online='y'");
$row = $result->fetch();
echo $row['online_users'];(#10850)
Re: Problem in PHP MYSql Query
hi nithinkk,
i m a newbie around here, just try this piece of code..
i m a newbie around here, just try this piece of code..
Code: Select all
<?php
$con = mysql_connect("localhost","root","") or die('Error Connect'); // Connecting to MySQL
mysql_select_db("test",$con) or die('Error in DB'); // Selecting DB
$res = mysql_query(" Select count(online) as cnt from login_details where online='y' ",$con); /* Fetching the count value*/
$row=mysql_fetch_array($res); // fetching the resulted row as array
echo $row['cnt']; // displaying the Count value
mysql_close($con); // Closing Connection
?>Re: Problem in PHP MYSql Query
That's a really horrible way of counting users online. Just set a 'last log in' timestamp when they log in, and count all the users where the timestamp is newer than 5 minutes ago. That way you don't need to bother setting the "online" flag back to 'n'.