View Full Version : Simple DB Query and Display values

03-19-2010, 08:13 PM
Hi all, I have an application where I have to display the score of each battle on an html page based on the DB table below. How would I do this?

For example, I would like to display something like this all on the same page (based on the 3 battles in example db table below):

Participants: 987 vs. 988
Score: 23 to 65

Participants: 658 vs. 784
Score: 45 to 75

Participants: 365 vs. 355
Score: 78 to 52

battle_id user_id1 user_id2 score1 score2

10 987 988 23 65
11 658 784 45 75
12 365 355 78 52

What is the code I need to have on the php page and also in the html portion to display the results? Please excuse my novice, I'm not a programmer and my developer left me mid way.. Just need advice on some simple stuff and hopefully learn a thing or two along the way.

Thanks so much for the help, much appreciated.

03-19-2010, 08:36 PM
I assume you showed us the names of your MySQL variables,
but what is the name of the table itself?

03-19-2010, 09:25 PM
Correct, the table name is just "battles".

03-20-2010, 01:30 AM

// Open Your MySQL Database with Your login.
$dbhost = 'hostname';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'databasename';

// Connect to the database.
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname) or die('Cannot select database');

// Query the database.
$query="SELECT * FROM battles ORDER BY battle_id ASC";
$result = mysql_query($query) or die(mysql_error());

// Close the database.

// Print your table title line.
<table cellspacing='5'>

// Fetch and Display Table Data.
while ($row = mysql_fetch_assoc($result)) {

echo "</table>";