SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie Q's - Retrieving information from database

    Hey,

    I am new at PHP/MySql so please forgive the beginner q's. I hope someone can help me out.

    I want to retrieve information from my database but want to display the results in different made html tables.

    I want to get a certain id number from the database and display the information in one of the html tables i have made, but i have a few tables and want to grab the last four id numbers inserted into the database and then display each id in a different table

    its like a shop, so whenver i update the databse the front page will change to the last four products according to the id number and be displayed in the 4 seperate html tables.

    How do i do something like this?
    Im guessing i would have to;

    Name each html table e.g <tr id="latest01">
    And write a different query for each table?

    how would i write the php to perform such a task?

    Thanks if anyone could help
    JT

  2. #2
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be something like:

    Code:
    <?php
    $sql = mysql_query("SELECT * FROM datatable ORDER BY id ASC LIMIT 4") or die(mysql_error());
    
    while ($row = mysql_fetch_array($sql)) {
    
    // Break out of PHP to output the table
    ?>
    
    <table width="500" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>ID</td>
    <td>Product Name</td>
    <td>Other Info</td>
    </tr>
    <tr>
    <td><?php echo $row[0]; ?></td>
    <td><?php echo $row[1]; ?></td>
    <td><?php echo $row[2]; ?></td>
    </tr>
    </table><br /><br /><br />
    
    <?php 
    } // End WHILE statement
    ?>
    Of course this will need to be edited to suit your needs, but basically the code grabs the latest 4 rows from the database (ordered by ID) and for each row, it outputs a table with the information from the database.

    Any questions post here and I'll help out,

    -Will

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks ima try it out now

  4. #4
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just added something to the end of my post as you replied ^^

    -Will


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
  •