1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Query SQL With PHP

Discussion in 'Software Development' started by Darkicon, Apr 23, 2010.

Thread Status:
Not open for further replies.
  1. Darkicon

    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.
     
  2. Darkicon

    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.
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/918698

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice