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 4 of 4
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Dynamic Tables and PHP?

    Hello,

    I wanna build a simple photo gallery using php and mysql.

    what i want to know is how to dynamicly build the tables and cell,
    so say i pull 13 images from the data base.

    and i want 3 columns and 4 rows.
    how would i do this in php?

    I'm a little confused as you may be able to tell.
    an example, or if anyone knows of a good tutorial, it would be a big help!

    thanks in advance for your time!
    -Ken

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    a very basic example:
    PHP Code:
    <?php
    // connect to db here

    $result mysql_query('SELECT * FROM photos LIMIT 12') or exit(mysql_error());
    while (
    $row mysql_fetch_assoc($result))
    {
        
    $photos[$row['photo_id']] = $row;
    }

    $chunks array_chunk($photos3);

    echo 
    '<table border="1">';
    foreach (
    $chunks as $value)
    {
        echo 
    '<tr>';
        foreach (
    $value as $sub_value)
        {
            echo 
    '<td><img src="/path/to/photos/' $sub_value['filename'] . '"></td>';
        }
        echo 
    '</tr>';
    }
    echo 
    '</table>';
    ?>

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    kool! thats what i was looking for, but could i ask one more question.

    what if i have 20 pics, and i only want to show 12 per page, then be able to move to the next 8.

    can this be done with just the sql statement?


    thanks again!
    -Ken

  • #4
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    search keyword "pagination"


  •  

    Posting Permissions

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