Results 1 to 2 of 2

Thread: Retrieving data from a database and displaying it in a table

  1. #1
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Retrieving data from a database and displaying it in a table

    ok I am new to databases!! Been using a database for years but I have never really done anything useful with it! I have my call of duty clan site. And I am making a challenge us form. When the form is completed, it puts the info into the database and sends me an email. Thats all perfect.

    I found a script that with some changes allowed me to connect to the database and present the information on a webpage. However, it doesn't look all that great. I want to display the information in a table.

    Here's the script I'm using........

    Code:
    <?php
    $dbhost = 'localhost';
    $dbuser = 'database_username';
    $dbpass = 'database_password';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    
    $dbname = 'database_name';
    mysql_select_db($dbname);
    
    $query = "SELECT * FROM challengeus";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    echo "alias :{$row['alias']} <br>" .
    "xfire : {$row['xfire']} <br>" . 
    "clanwebsite : {$row['clanwebsite']} <br><br>";
    }
    mysql_close($conn);
    
    ?>
    
    <html>
    <table border="5" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="100%" id="AutoNumber2" bgcolor="#C0C0C0">
      <tr>
        <td width="14%" align="center">Clan</td>
        <td width="14%" align="center">Clan Website</td>
        <td width="14%" align="center">Number of Players</td>
        <td width="14%" align="center">Gametype</td>
        <td width="14%" align="center">Map</td>
        <td width="15%" align="center">Date</td>
        <td width="15%" align="center">Result</td>
      </tr>
      <tr>
        <td width="14%" align="center">&nbsp;</td>
        <td width="14%" align="center"><?php {echo "{$row['clanwebsite']}";} ?></td>
        <td width="14%" align="center">&nbsp;</td>
        <td width="14%" align="center">&nbsp;</td>
        <td width="14%" align="center">&nbsp;</td>
        <td width="15%" align="center">&nbsp;</td>
        <td width="15%" align="center">&nbsp;</td>
      </tr>
    </table>
    </html>
    The HTML part does create the table I want to use. But, am I supposed to use html to display info from a database??

    I have no clue as to how to solve this one!!

    Thanks in advance to anyone who can help.

    Smithster

  2. #2
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool

    Ok, Ive sorted it! Got it working in the way I wanted. Here's the script.....
    Code:
    <?php
    $dbhost = 'localhost';
    $dbuser = 'dbuser';
    $dbpass = 'dbpass';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    
    $dbname = 'dbname';
    mysql_select_db($dbname);
    
    $query = "SELECT * FROM challengeus";
    $result = mysql_query($query) 
    or die(mysql_error()); 
    print " 
    <table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"100&#37;\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\"><tr> 
    <td width=100>Clan:</td> 
    <td width=100>ClanWebsite:</td> 
    <td width=100>Number of Players:</td> 
    <td width=100>Gametype:</td> 
    <td width=100>Map:</td> 
    <td width=100>Server:</td> 
    <td width=100>Date:</td> 
    <td width=100>Result:</td> 
    </tr>"; 
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    { 
    print "<tr>"; 
    print "<td>" . $row['clan'] . "</td>"; 
    print "<td>" . $row['clanwebsite'] . "</td>"; 
    print "<td>" . $row['players'] . v . $row['players'] . "</td>"; 
    print "<td>" . $row['gametype'] . "</td>";
    print "<td>" . $row['map'] . "</td>";
    print "<td>" . $row['server'] . "</td>";
    print "<td>" . $row['date'] . "</td>";
    print "<td>" . $row['result'] . "</td>"; 
    print "</tr>"; 
    } 
    print "</table>"; 
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •