need help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
doforumda
Forum Newbie
Posts: 16
Joined: Thu Dec 25, 2008 1:07 am

need help

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: need help

Post 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.
doforumda
Forum Newbie
Posts: 16
Joined: Thu Dec 25, 2008 1:07 am

Re: need help

Post 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
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: need help

Post 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."; 
 
doforumda
Forum Newbie
Posts: 16
Joined: Thu Dec 25, 2008 1:07 am

Re: need help

Post 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
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: need help

Post 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.";
 
doforumda
Forum Newbie
Posts: 16
Joined: Thu Dec 25, 2008 1:07 am

Re: need help

Post 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
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: need help

Post by Ziq »

1) Try to understand this example http://ru2.php.net/manual/en/mysql.examples.php
2) Read about mysql_connect, mysql_select_db and other functions.
Post Reply