Results 1 to 5 of 5

Thread: [RESOLVED] rows display picture

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] rows display picture

    I have this image source <img src=....> I want it to be displayed in a table that has as many rows as the picture in the database increases but limitted to five rows.

    For exmaple, if the table has one picture,

    then

    Code:
    <table>
    <tr><td><img src....>
    </td></tr></table>
    But if the database has 2 pictures, then another row is automatically added to the page, that would be second row to store second picture.

  2. #2
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    Resolved Re: rows display picture

    Well I don't completely understand what you're trying to do but if it's what I think, then use a loop to display the pictures depending on how many there are (up to five):

    PHP Code:
    $numPics count($pics);
    if (
    $numPics 5) {
      for (
    $i 0$i <= 4$i++) {
        echo 
    "<tr><td><img src=\"$pics[$i]\"></td></tr>";
      }
    } else {
      for (
    $i 0$i <= $numPics 1$i++) {
        echo 
    "<tr><td><img src=\"$pics[$i]\"></td></tr>";
      }

    Just put the path to the pictures into the $pics array in any way you see fit, whether randomly or whatever, and have it display up to five of them.
    Last edited by asterix299; May 17th, 2007 at 10:05 PM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: rows display picture

    Not quite what I wanted. See I want a table that can list many photos in "rows" but each row can consist of only five photos. Which means, the first rows has five pictures, second row has five pictures and so on. ...

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: rows display picture

    a bit messy. you get the idea, though.
    PHP Code:
    <?php
      $pictures 
    = array("picture1""picture2""picture3""picture4""picture5""picture6""picture7");
      
    $ii 0//index for the row
      
    $cols 5//number of columns in each row
      
    $ncol true//whether or not to make a new column
      
    for($i 0$i <= count($pictures) - 1$i++){
        
    $ii++;

        
    //end a row?
        
    if($ii $cols){
          
    $ii 0//reset row index
          
    echo '</tr>' "\n";
          
    $ncol true;
        }

        
    //start a new row?
        
    if($ncol == true){
          
    $ncol false;
          echo 
    '<tr>' "\n";
        }

        
    //display image
        
    echo '  <td><img src="' $pictures[$i] . '" /></td>' "\n";

        
    //is the table finished?
        
    if($i == count($pictures) - 1){
          
    //finish filling the row if we need to
          
    if($ii $cols){
            for(
    $j $ii$j $cols 1$j++){
              echo 
    '  <td>&nbsp;</td>' "\n";
            }
          }
          echo 
    '</tr>' "\n";
        }
      }
    ?>
    Last edited by kows; May 18th, 2007 at 02:24 AM.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: rows display picture

    Kows, thank you for giving me the idea. I went ahead and wrote up my own code:

    PHP Code:
    <?php
      $pictures 
    = array("picture1""picture2""picture3""picture4""picture5""picture6""picture7""picture8""picture9""picture10""picture11");
      
    $ii 0//index for the row
      
    $cols =2//number of columns in each row
      
    for($i 0$i <= count($pictures) - 1$i++)
      {
          
    // increment row index
          
    $ii++;
          
          if (
    $i ==0)
          {
             echo 
    "<table border=0>\n<tr>\n";

          }
          
           echo 
    "<td>$pictures[$i]</td>\n";

          
          if (
    $ii >= $cols)
          {
             echo 
    "</tr>\n<tr>\n";
             
    $ii=0//reset the index row
          
    }
          
          if (
    $i==count($pictures)-1)
          {
             echo 
    "</tr></table>";
          }
      }

    ?>

Posting Permissions

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



Click Here to Expand Forum to Full Width