1

can't find the answer alone. I want to connect mySQL server and count the users online. After that, print it out as an number & draw picture bar according user number.

This is what I managed to pull.

<?PHP
//db info
  define('mySQL_hostname', '192.0.0.1');  //database IP
  define('mySQL_database', 'mywebdb');  //database name
  define('mySQL_username', 'root');  //database user
  define('mySQL_password', 's1mpl3');  //database password
//connects to mysql
  $db_link = mysql_pconnect( mySQL_hostname, mySQL_username, mySQL_password )
    or die( 'Error connecting to mysql<br><br>'.mysql_error() );
//connects to Database
  $db_select = mysql_select_db( mySQL_database, $db_link )
    or die( 'Error connecting to Database<br><br>'.mysql_error() );
//selects desired table
   $chars= mysql_query("SELECT `online` FROM `users` where `online`=1");
   $rows = mysql_num_rows($chars);
    echo "<b><em>".$rows."<em></b>"; //prints out the $x number of players online
?>

What i want to do with this... to make ~150px brown bar and put some green pixels for each user online. Example 50 users = 100%. 0 users = 1% I did a css file inside PHP and managed to draw brown bar.

#bar_empty {
    background-color: #401800;
    width: 150px;
    height: 6px;
}

So "echo ""; now gives a brown bar to work on, but i have no idea how to set bar "worth of the pixel" and how print them out. Any ideas would be great.

  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jan 29 '16 at 17:31
  • Ok, but can we not focus on sql things? – user3315509 Jan 29 '16 at 17:52

0 Answers0