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 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2012
    Location
    Philippines
    Posts
    35
    Thanks
    5
    Thanked 0 Times in 0 Posts

    how to display all data in my table?

    how can i display all data in my table? for example i have a table that has 1 column and i want to display all the data inside that column not just the latest data but all of it how can i do it?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Use a loop along with a fetch function. Most people use a "while" loop, but I prefer a "for" loop.

    Assuming you're using MySQL..

    PHP Code:
    //Your query
    $sql "SELECT column1 FROM table1";
    // query results
    $result mysql_query($sql);
    //Don't forget to check for errors!
    if (!result)
    {
        die(
    "Query error. Query: $sql<br>Error:".mysql_error());
    }
    //loop through the results
    $cnt mysql_num_rows($result);
    for (
    $i 0$i $cnt$i++)
    {
        
    $row mysql_fetch_array($result);
    }
    //Do whatever you need to with the data now
    print_r($row); 


  •  

    Posting Permissions

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