Page 1 of 1
need help
Posted: Thu Dec 25, 2008 1:14 am
by doforumda
hi
i need help
i have a table with name of "active_users". When any user login then that user is automatically added to this table. what i want to accomplish is to count the number of users that are in this table and then display that figure. i am doing this in php+mysql. So please help me if anybody know the solution for this. i am waiting
Re: need help
Posted: Thu Dec 25, 2008 1:19 am
by requinix
doforumda wrote:i am waiting
Careful, you sound impatient. A bad attitude towards us isn't going to help you.
Code: Select all
SELECT COUNT(*) FROM `active_users`
Use the mysql functions to get the result of that query.
Re: need help
Posted: Thu Dec 25, 2008 4:07 am
by doforumda
well i already tried this but it displays the following
There are Resource id #4 users currently viewing this site.
i used the following codes and query
$active_user_query = mysql_query("select count(*) from active_users");
echo "<br>There are ".$active_user_query." users currently viewing this site.";
and i apologize saying i am waiting
Re: need help
Posted: Thu Dec 25, 2008 4:59 am
by pbs
Try this
Code: Select all
$active_user_query = mysql_query("select count(*) from active_users");
echo "<br>There are ".mysql_num_rows($active_user_query)." users currently viewing this site.";
Re: need help
Posted: Thu Dec 25, 2008 6:55 am
by doforumda
it give me this warning
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\wamp\www\Login\login.php
how can i remove this warning
Re: need help
Posted: Thu Dec 25, 2008 7:26 am
by Ziq
You should read the manuals about this. For example, PHP manual for MySQL.
http://php.net/mysql
This code is incorrect. Try this one
Code: Select all
$active_user_query = mysql_query("select count(*) from active_users") or die(mysql_error());
echo "<br>There are ".mysql_result($active_user_query, 0)." users currently viewing this site.";
Re: need help
Posted: Thu Dec 25, 2008 7:38 am
by doforumda
thanks manits working now when place this
$active_user_query = mysql_query("select count(*) from active_users") or die(mysql_error());
echo "<br>There are ".mysql_result($active_user_query, 0)." users currently viewing this site.";
then it said that No database selected then i give it the database name then it starts wrking
thank you again
Re: need help
Posted: Thu Dec 25, 2008 7:50 am
by Ziq