display data in ROW & COLUMN wise

Discussion in 'PHP' started by badmasketa, May 13, 2008.

  1. #1
    i do have image table like this

    id image
    1 cat.jpg
    2 dog.jpg
    3 apple.jpg
    4 duck.jpg
    5 tea.jpg
    6 eye.jpg

    now what i want is i wanna display those images in column n row wise(there may be more than that datas), can anybody please help me out...
    i want to display like this

    cat.jpg dog.jpg apple.jpg
    duck.jpg tea.jpg eye.jpg

    Please help me out guys...
    my code is here but it displays in 1 column only....

    <?
    include 'connect.php';

    $wp = mysql_query("SELECT * FROM wallpapers order by id asc limit 6");
    while($row = mysql_fetch_array($wp)){
    $id = $row["id"];
    $thumb = $row["thumb"];

    echo "<table>";
    echo "<tr>";
    echo "<td><img src=\"wallpapers/thumb/$thumb\" width=\"120\" height=\"90\"></td>";
    echo "</tr>";
    echo "</table>";
    }
    ?>
     
    badmasketa, May 13, 2008 IP
  2. msaqibansari

    msaqibansari Peon

    Messages:
    84
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi
    
    <?
    include 'connect.php';
    
    $wp = mysql_query("SELECT * FROM wallpapers order by id asc limit 6");
    while($row = mysql_fetch_array($wp)){
    $id = $row["id"];
    $thumb = $row["thumb"];
    
    echo "<table>";
    echo "<tr>";
    echo "<td><img src=\"wallpapers/thumb/$thumb\" width=\"120\" height=\"90\"></td>";
    echo "</tr>";
    echo "</table>";
    }
    ?>
    
    Code (markup):
    use following code

    
    <?
    include 'connect.php';
    
    $wp = mysql_query("SELECT * FROM wallpapers order by id asc limit 6");
    echo "<table>";
    echo "<tr>";
    $counter = 1;
    while($row = mysql_fetch_array($wp))
    {
       $id = $row["id"];
       $thumb = $row["thumb"];
    
       echo "<td><img src=\"wallpapers/thumb/$thumb\" width=\"120\" height=\"90\"></td>";
    if ($counter==5)   {
       echo "</tr><tr>";
       $counter = 0;
    }
    $counter++;
    }
    echo "</tr>";
    echo "</table>";
    ?>
    
    PHP:
     
    msaqibansari, May 13, 2008 IP
  3. badmasketa

    badmasketa Well-Known Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    yeah thats exactly what i was looking for :D
    thanks dude
    AND
    it would be more better
    If you add the code for like PAGINATION ( Previous- Next)

    can you please do that for me??
     
    badmasketa, May 13, 2008 IP