Tyrnt,
First lets tackle the who's online problem. I'm the administrator for a site that has a very advanced version of this, and I'll give you the rundown.
It sounds like you'll have registered users, with their information stored in a table - this will make things very easy.
In your members table, add two fields named online, and last_login:
alter table tbl_name add online char(1);
alter table tbl_name add login_last timestamp(14);
the mysql data type timestamp(14) is the time set up like this:
YYYYMMDDhhmmss
Thats 4 digit year, 2 digit month, 2 digit day, 2 digit hour, 2 digit minute, and 2 digit second.
Once this is done, for now, set the online value for everyone to 'n', and the login_last value to the current date and time:
update tbl_name set online='n';
update tbl_name set timestamp='20010128010300';
Now, you will need to create a piece of code that will be included in all scripts on your site, to make sure people are still logged in, and to log them out if they are not (you can't always count on people being responsible enough to log themselves out of a site by clicking on a 'logout' button. This script, with every click on the site, will update the user's login time, and log them out if their login time was more than 15 minutes ago.
We'll call this script online.php:
<?php
mysql_connect("localhost", username, pass);
mysql_select_db('db_name');
$current_time=date("YmdHis");
// this is the time in the mysql
// timestamp(14) format.
$time_fifteen_ago=$current_time - 900;
//this creates the time 15 minutes ago
// (900 seconds = 15 minutes)
$update = "update tbl_name set login_last='$current_time'";
$dotheupdate=mysql_query($update);
// grab the username and last login
// from anyone still logged in
$check = "select username, login_last from tbl_name where online like 'y'";
$dothecheck = mysql_query($check);
//logout users inactive for 15 minutes:
while ($row=mysql_fetch_array($dothecheck)){
if ($row[1] < $time_fifteem_ago){
$logout = "update tbl_name set online='n' where username='$row[0]'";
$dothelogout = mysql_query($logout);
}
}
?>
That's it for online.php, but now you'll have to add a snippet of code to your login page that sets the field 'online' in the mysql table to 'y' when they login.
That should work fairly well. You can see a much more advanced version in www.platinumpersonals.com - there is a free user signup on the site, so you dont need to pay for anything.
Now for your second question:
To check how many entries there are in a table:
select count(*) from tbl_name;
To get the largest number in a numeric field:
max(field_name);
That should work for ya. If you have any questions, just respond to this post, and I'll be contacted.
Thanks!
-=Lazzerous=-