SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot AirFor's Avatar
    Join Date
    Oct 2010
    Berrigan, NSW, Australia
    0 Post(s)
    0 Thread(s)

    Need help displaying database to HTML table

    So I'm trying to display a database in a HTML table using HTML and PHP to show the results. I'm a novice with PHP and trying to get the following to work:

    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    <script type="text/javascript" src="jquery-latest.js"></script>
    <script type="text/javascript" src="jquery.tablesorter.js"></script>
    <form action="insert.php" method="post">
    Game Name: <input type="text" name="gamename">
    Genre: <input type="text" name="genre">
    Metacritic Score: <input type="text" name="score">
    Completed?: <input type="text" name="completed">
    <input type="submit">
    <input type="reset">
    @mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM Games";
    <table id="myTable" class="tablesorter">
    <th>Game Name</th>
    <th>Metacritic Score</th>
    while ($i < $num) {
    <td><?php echo $f1; ?></td>
    <td><?php echo $f2; ?></td>
    <td><?php echo $f3; ?></td>
    <td><?php echo $f4; ?></td>
    I'm not sure what the problem is?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Atlanta, GA, USA
    73 Post(s)
    0 Thread(s)
    Welcome to the world of Database Interaction.

    Please dont feel like i'm picking on you, but you've got quite a few things to adjust here.
    #0: mysql as a library is being deprecated; you should look at moving to mysqli or PDO.
    #1: mysql_numrows is not a function (mysql_num_rows)
    #2: Consider using a while construct that uses the result resource's own pointer (while($row = mysql_fetch_assoc($result)) { )
    #3: If you do #2, your $f definitions can be simplified using a list (list($f1,$f2,$f3,$f4) = $row)... or alternatively you can just use the $row variable in your echos (<?php echo $row['gamename']; ?>)
    #4: If you're doing this in a development area, you should consider turning error displays on (#1) until you get the script doing what it should be.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Posting Permissions

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