Jump to content

count statement


Lone_Ranger
Go to solution Solved by Ch0cu3r,

Recommended Posts

What I'm trying to say here is, if the column STATUS is counted and in that column there are no rows that contain "ONLINE"  then I want the result to show as "There Are Currently No Users Online" else if there are rows in that column that have "ONLINE" in them then it show them in a list eg. DAVE, STUART, PAUL, DONNA

if (count($contents[status]='online') === 0) {

echo "<p align=center> There Are No Users Currently Online</p>";

}
else
{
$resultcont = mysql_query("SELECT * FROM userdb where status='online' order by id DESC LIMIT 0,15");
while($contents = mysql_fetch_array($resultcont))
{

echo "<a href=http://www.sentuamessage.com/profile?who=$contents[id]>$contents[name]</a>";
 }

this is how I thought it would be. I realise that it is wrong but trying to figure how I would get this working. Any help?

 

I did have it originally as "if (count($contents[online]) === 0) {" but realised this was wrong as there is no column called online.

 

 

 

Link to comment
Share on other sites

  • Solution

Let MySQL tell you how many users are online

$resultcont = mysql_query("SELECT id, name FROM userdb WHERE status='online' ORDER BY id"); // get all users where status is online

$usersOnline = mysql_num_rows($resultcont); // how many results where returned from the query

// if there are users online
if($usersOnline > 0)
{
	echo "<p>There are $usersOnline:</p>"; // display how many users are online

    // then list the users
	while(list($id, $name) = mysql_fetch_row($resultcont))
	{
		echo "<a href=http://www.sentuamessage.com/profile?who=$id>$name</a>";
	}
}
// no users online 
else
{
	echo "<p align=center>There Are No Users Currently Online</p>";
}
Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.