Solved: Query SQL With PHP

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Darkicon

Thread Starter
Joined
Feb 12, 2008
Messages
265
I'm trying to query information from an SQL database and output it to an HTML table. I am a complete newbie to PHP and SQL coding so I have no idea what I'm doing, lol.

The DB name is eggroup_rank. The table is css_rank and the the following fields are what I need to query from:

rank_id
nick
kills
deaths
headshots
sucsides (Yes, spelled like that)
played_time

I tried to write a PHP file to query the information and output it to a table but it keeps messing up. It'll display the ID and name but nothing else.

Code:
<?php
 mysql_connect("Database_Host", "Username", "Password") or die(mysql_error()); 
 mysql_select_db("eggroup_rank") or die(mysql_error()); 

$result = mysql_query("SELECT * FROM css_rank") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Name</th> <th>Kills</th> <th>Deaths</th> <th>Headshots</th> <th>Suicides</th> <th>Time Played</th> </tr>";
while($row = mysql_fetch_array( $result )) {
	echo "<tr><td>"; 
	echo $row['rank_id'];
	echo "</td><td>"; 
	echo $row['nick'];
	echo "</td></tr>"; 
	echo $row['kills'];
	echo "</td></tr>"; 
	echo $row['deaths'];
	echo "</td></tr>"; 
	echo $row['headshots'];
	echo "</td></tr>"; 
	echo $row['sucsides'];
	echo "</td></tr>"; 
	echo $row['played_time'];
	echo "</td></tr>"; 
} 

echo "</table>";
?>

Here's what that code outputs: http://ip.weareepic.com/rank.php

Any help is greatly appreciated. Also, yes, I put in the host, username and password all correctly, just blanked it out in the code.
 

Darkicon

Thread Starter
Joined
Feb 12, 2008
Messages
265
Nevermind. I figured it out. I was supposed to use "echo "</td><td>"; " after each section.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top