Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts

    why isn't this database list page not working?

    hi, got a problem here....

    i am trying to list contents of a database and the page isn't working, nothing is listing in the table, there is data in the the database. here is the code:

    cdlist.php

    <?php
    //following code taken from: http://dalibor.dvorski.net/downloads...gWithXAMPP.pdf
    // Connect and select a database
    mysql_connect("localhost", "root", "");
    mysql_select_db("cdcat");

    //run a query
    $result = mysql_query("SELECT * FROM cdcat");
    ?>

    <html>

    <head>
    <title>CD Catalogue full listing:</title>
    </head>

    <body>
    <h1>CD Catalogue full listing:</h1>

    <table border="1" cellpadding="2" cellspacing="3" summary="table holds cd catalogue database">
    <tr>
    <th>ID</th>
    <th>CD Title</th>
    <th>Artist</th>
    <th>Genre</th>
    </tr>

    <?php

    //loop through all table rows while ($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>". $row['Id'] . "</td>";
    echo "<td>". $row['Title'] . "</td>";
    echo "<td>". $row['Artist']. "</td>";
    echo "<td>". $row['Genre']. "</td>";
    echo "<tr>";
    }

    //free result memory and close database connection
    mysql_free_result($result);
    mysql_close();
    ?>
    </table>
    </body>

    </html>

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Try changing:

    //loop through all table rows while ($row = mysql_fetch_array($result))
    {


    To:

    //loop through all table rows
    while ($row = mysql_fetch_array($result)) {
    Leonard Whistler

  • Users who have thanked Len Whistler for this post:

    nielsonp (05-21-2008)

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    cheers Len.
    thanks for rapid response! it worked!!


  •  

    Posting Permissions

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