Jump to content

Displaying Data From Mysql


shadrxninga

Recommended Posts

Ok... I need some help - I want to show a players balance in a game beside there name (Balance is in mysql database)I can do that but... - I also want to show if there online or offline at the same time( This is stored in a different database)

I have the code which says whether they are online or offline

<?PHP

// Conect to the Mysql Server
$connect = mysql_connect("localhost","scswccla_bukkit","********");

//connect to the database
mysql_select_db("scswccla_bukkit");

//query the database
$query = mysql_query("SELECT * FROM users_online WHERE online = 1");

//title
echo "<font size='100'>NovaCraft Users</font><br>";

// fetch the results / convert into an array

        WHILE($rows = mysql_fetch_array($query)):


	        $users = $rows['name'];



	echo "<font color='black'>|Online|<br><font color='green'>$users</font></font><br>";

	 endwhile;

//query the database
$query = mysql_query("SELECT * FROM users_online WHERE online = 0");

//title
echo "<font color='black'>|Offline|</font><br>";

// fetch the results / convert into an array

        WHILE($rows = mysql_fetch_array($query)):


	        $users = $rows['name'];



	echo "<font color='red'>$users</font><br>";

	 endwhile;

?>

 

Here is the page: www.scswc.com/Offline_Users.php displaying that

 

But I want to Create something like this:

 

Nocvacraft Players

 

|Online|

Name:Player Balance:$20

|Offline|

Name:Player Balance:$15

 

Here is what I have tried:

<?PHP

// Conect to the Mysql Server
$connect = mysql_connect("localhost","scswccla_bukkit","**********");

//connect to the database
mysql_select_db("scswccla_bukkit");

//query the database
$query = mysql_query("SELECT * FROM users_online WHERE online = 1");
$query2 =mysql_query("SELECT * FROM iBalances WHERE player = $users");

//title
echo "<font size='100'>NovaCraft Users</font><br>";

// fetch the results / convert into an array

        WHILE($rows = mysql_fetch_array($query) $rows2 = mysql_fetch_array($query2)):


	        $users = $rows['name'];
			$balance = $rows2['balance'];



	echo "<font color='black'>|Online|<br><font color='green'>Name:$usersBalance:$balance</font></font><br>";

	 endwhile;

//query the database
$query = mysql_query("SELECT * FROM users_online WHERE online = 0");

//title
echo "<font color='black'>|Offline|</font><br>";

// fetch the results / convert into an array

        WHILE($rows = mysql_fetch_array($query)):


	        $users = $rows['name'];



	echo "<font color='red'>$users</font><br>";

	 endwhile;

?>

 

I know I am trying to use a variable before it is been set - but if I don't how

 

I have tried this as well...

<?PHP

// Conect to the Mysql Server
$connect = mysql_connect("localhost","scswccla_bukkit","**********");

//connect to the database
mysql_select_db("scswccla_bukkit");

//query the database
$query = mysql_query("SELECT * FROM users_online WHERE online = 1");

//title
echo "<font size='100'>NovaCraft Users</font><br>";

// fetch the results / convert into an array

        WHILE($rows = mysql_fetch_array($query)):


	        $users = $rows['name'];




	echo "<font color='black'>|Online|<br><font color='green'>Name:$users</font></font><br>";

	 endwhile;

//query the database
$query = mysql_query("SELECT * FROM users_online WHERE online = 0");

//title
echo "<font color='black'>|Offline|</font><br>";

// fetch the results / convert into an array

        WHILE($rows = mysql_fetch_array($query)):


	        $users = $rows['name'];



	echo "<font color='red'>$users</font><br>";

	 endwhile;
$query = mysql_query("SELECT * FROM iBalances WHERE player = $users");

WHILE($rows = mysql_fetch_array($query)):


	        $balance = $rows['balance'];



	echo "<font color='red'>$users $balance</font><br>";

	 endwhile;
//

?>

 

 

Can you use variables in mysql_query()?Is that why it isn't working?

 

This is my first php script so if I need to give you more information for you to help me just tell me

 

Thanks


 

Here is database pictures

 

iBalances

ets60z.png

users_online

8w9o42.png

Link to comment
https://forums.phpfreaks.com/topic/225586-displaying-data-from-mysql/
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.