Jump to content

count statement


Lone_Ranger

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
https://forums.phpfreaks.com/topic/284572-count-statement/
Share on other sites

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>";
}
Link to comment
https://forums.phpfreaks.com/topic/284572-count-statement/#findComment-1461474
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.