SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question displaying N images in a row prob??

    Hello everybody!!!
    I am getting problem in displaying images after fetching from the database.
    I want to display 4 images in one row .But i didnt know the idea..
    Could anyone help me to display the N no of images in a row..
    Thanks you in advance

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you do this in your PHP code by opening a table and initializing a counter. echo the <tr> tag. then display a picture in a td tag pair and increment the counter. keep doing that until the counter is 4, at which time you echo a </tr> tag, reset the counter, and keep going.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    or you could float the images with CSS, which will keep the page liquid, whereas a TABLE with a fixed number of TDs (like 4) may require horizontal scrolling

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict Php_penguin's Avatar
    Join Date
    Aug 2004
    Location
    Colwyn Bay, Wales, UK
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $counter "1";
    for(
    $i 0$i count($images); $i++) {
    if(
    $counter == 4) {
    echo 
    "</tr>";
    $counter 1;
    } else if(
    $counter == 1) {
    echo 
    "<tr>";
    $counter++;
    } else {
    $counter++;
    }
    echo 
    "<td><img src='".$images[$i]."'></td>";
    }
    if(
    $counter != 4) {
    echo 
    "</tr>";

    simple!

  5. #5
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use counters
    like
    PHP Code:
    $i=0;
    while(
    $rw=mysql_fetch_array($qr)){
    //echo images
    if($i%4==0) echo "</tr>";
    $i++; 
    Power of Knowledge

  6. #6
    SitePoint Enthusiast onion2k's Avatar
    Join Date
    Dec 2005
    Location
    UK
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <div style="float: left; width: 33%; text-align: center;"><img src="blah.jpg"></div>


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
  •