Results 1 to 7 of 7

Thread: [RESOLVED] Displaying All Records

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] Displaying All Records

    My code is only showing one record from the database how would i get it to show all the records from the database and not just one.?

    PHP Code:
    <?php
    include("config.php");

     
    mysql_connect("$host""$username""$password");
     
    mysql_select_db($db) or die(mysql_error());

    // Retrieve all the data from the "example" table
    $result mysql_query("SELECT * FROM ip")
    or die(
    mysql_error());  

    // store the record of the "example" table into $row
    $row mysql_fetch_array$result );
    // Print out the contents of the entry 

    echo "IP: ".$row['ip'];
    echo 
    " Reason: ".$row['Reason'];

    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Displaying All Records

    PHP Code:
    while($row mysql_fetch_array$result )) {
    echo 
    "IP: ".$row['ip'];
    echo 
    " Reason: ".$row['Reason']."<br />"

    You need to loop through all the returned rows of the query.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Displaying All Records

    What would i need to do if there is no records how to i get it to display a message?

    EDITED:::- I just added a new IP address and now it dosent show them on the display page but when i add another one it then displays the second ip address and not the first one and displays all the reson from there on.
    http://prksoftware.co.uk/display.php
    Last edited by Jamie_Garland; Oct 14th, 2008 at 05:15 AM.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Displaying All Records

    Can you post all your code?

    If there are no IPs, you can use the mysql_num_rows to check if there is at least one returned from your SQL statement or not.


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Displaying All Records

    Config.php

    PHP Code:
    <?
    // Please edit the variables below:

        //Set the MySQL server address (usually localhost)
        $host = "localhost";
        //Enter the login name you wish to access your database with
        $username = "web181-ipbanner";
        //Enter the password to access the database
        $password = "d82f1fc";
        //Enter the database you wish to use
        $db = "web181-ipbanner";

    ?>
    display.php

    PHP Code:
    <?php 
    include("config.php"); 

    mysql_connect("$host""$username""$password"); 
    mysql_select_db($db) or die(mysql_error()); 

    // Retrieve all the data from the "example" table 
    $result mysql_query("SELECT * FROM ip"
    or die(
    mysql_error());   

    // store the record of the "example" table into $row 
    $row mysql_fetch_array$result ); 
    // Print out the contents of the entry 

    while($row mysql_fetch_array$result )) {
    echo 
    "<br>IP:<br> ".$row['ip'];
    echo 
    "<br>Reason:<br> ".$row['Reason']."<br /><hr>"


    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Displaying All Records

    PHP Code:
    // store the record of the "example" table into $row
    $row mysql_fetch_array$result ); 
    the problem is with this line. You fetch the first entry from the database and do nothing with it. It's the same command that's in the while condition so you don't need it separately above it. That's why the first entry doesn't show up. It gets loaded in $row, and then when the loop starts gets overwritten with the 2nd entry.


    Has someone helped you? Then you can Rate their helpful post.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Displaying All Records

    shall i remove this code.

    PHP Code:
    // store the record of the "example" table into $row 
    $row mysql_fetch_array$result ); 
    // Print out the contents of the entry 
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

Posting Permissions

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



Click Here to Expand Forum to Full Width