Hello everyone,

I have a database with a list of characters and I would like to display which characters are currently logged in on a webpage I have.

My database looks like this:

`characters` (`account`, `name`, `online`) VALUES (6, 'Frod', 1);

I hope that makes sense.

So if 'online' = 1 the character is currently logged in.
I would like to access the database and pull only the names that have the value of 1 in 'online' and display them in alphabetical order (if possible).

Can this be done in MySQL?

I'm not very knowledgeable when it comes to creating code. This is what I've tried.

<?php
@mysql_connect("localhost","root","ascent") OR die(mysql_error());
@mysql_select_db("funcharacters") OR die(mysql_error());
$query = @mysql_query("SELECT * FROM characters WHERE online = 1") OR die(mysql_error());
$whoonline = @mysql_num_rows($query);
echo "Who's Online: $whoonline";
?>

However that code only displays the number of people online.

Any help is appreciated.

it may be something like this...i havent tasted the code.

/*Database connection*/
 
/*below our query*/
$query= mysql_query("SELECT name FROM characters WHERE online ='1'  ORDER BY name") OR die(mysql_error());
$count=mysql_num_rows($query);
/*check if there is anyone online*/
if($count>0){
   $msg="There are $count Members Online<br/>";
}else{
 $msg="There are No members online<br/>";
}
echo"$msg<br/>";/* display message*/
while($row=mysql_fetch_array($query)){
$name = $row['name'];
echo "$name is  Online<br/>";
}
commented: Excellent Knowledge +1

I'll give it a try. Thanks for the reply. Will post results.

Works perfectly! Thank you very much.

You are welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.