PHP Table help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HexOnxOnx
    Senior Member
    • Apr 2003
    • 638
    • 3.7.x

    PHP Table help

    Hi all

    Below is some code that I need help with. It is not vB related but is for a photo site. The code displays a members photos on a table with only one column. Each photo is displayed in it's own row in that one column so each photo appears below the previous like this:

    photo
    photo
    photo
    photo

    This makes the page rather long if someone has alot of photos.


    I would like to change this code so that there are two columns so that it would look like this

    photo photo
    photo photo
    photo photo

    below is the code, it's not that hard to figure out, I just have no clue to do what I want above.

    PHP Code:
       $imgdir=strtolower("photo/$profil[nick]");
        if(
    is_dir($imgdir)) $timgs=ReadThumbImages($profil["nick"]);
        if(
    is_array($timgs)) {
         
    $viewImgs "<table border='0' cellpadding='0' cellspacing='0' bgcolor='#CCCCCC'>
           <tr>
           <td> 
             <table width='100%' border='0' cellspacing='1' cellpadding='4'>"
    ;
         foreach(
    $timgs as $timg) {
          
    $imgNrs++;
          
    $viewImgs .= "<tr bgcolor='#FFFFFF'>"$i++;
          
    $viewImgs .= "<td align='center'><a href=\"JavaScript: gow('$imgdir/b_".substr($timg,2,strlen($timg))."')\"><img src='$imgdir/$timg' alt='$timg' border=0></a></td>";
          
          
    $viewImgs .= "</tr>"//$i=0;}
         
    }
         
         
    $viewImgs .= "</table>
            </td>
           </tr>
          </table>"
    ;
        }
       } 

    Thanks for any help!
    http://www.icecreamforum.com
  • Icheb
    Senior Member
    • Nov 2002
    • 1291

    #2
    PHP Code:
     $i 1;
      while (do 
    whatever you want) {
           if (
    $i != 0) {
              
    // display content in left column
           
    }
           else {
              
    // display content in right column
           
    }
           
    $i++;
        } 
    That would display your photos in the order of

    1 2
    3 4
    5 6
    7 8

    Having it in

    1 5
    2 6
    3 7
    4 8

    is certainly also possible and not much harder.

    Comment

    • HexOnxOnx
      Senior Member
      • Apr 2003
      • 638
      • 3.7.x

      #3
      Thanks but how would I put that in my code above? I am lost here!
      http://www.icecreamforum.com

      Comment

      • Icheb
        Senior Member
        • Nov 2002
        • 1291

        #4
        Put it in your foreach().

        Comment

        • HexOnxOnx
          Senior Member
          • Apr 2003
          • 638
          • 3.7.x

          #5
          Well thanks anyways. What I needed was for someone to alter the code for me because I have no clue on what to do. I didn't write the code. I just know enough to know that code controls the images. I have no idea how to even insert it in the foreach() part.
          http://www.icecreamforum.com

          Comment

          • Icheb
            Senior Member
            • Nov 2002
            • 1291

            #6
            Try this.

            PHP Code:
            $imgdir=strtolower("photo/$profil[nick]");
                   if(
            is_dir($imgdir)) $timgs=ReadThumbImages($profil["nick"]);
                   if(
            is_array($timgs)) {
                    
            $viewImgs "<table border='0' cellpadding='0' cellspacing='0' bgcolor='#CCCCCC'>
                      <tr>
                      <td> 
                        <table width='100%' border='0' cellspacing='1' cellpadding='4'>"
            ;
                    
            $counter 1;
                    foreach(
            $timgs as $timg) {
                     
            $imgNrs++;
                     if (
            $counter != 0) {
                     
            $viewImgs .= "<tr bgcolor='#FFFFFF'>"$i++;
                     
            $viewImgs .= "<td align='center'><a href=\"javascript: gow('$imgdir/b_".substr($timg,2,strlen($timg))."')\"><img src='$imgdir/$timg' alt='$timg' border=0></a></td>";
                 }
                     else {
                     
            $i++;
                      
            $viewImgs .= "<td align='center'><a href=\"javascript: gow('$imgdir/b_".substr($timg,2,strlen($timg))."')\"><img src='$imgdir/$timg' alt='$timg' border=0></a></td>";
                      
                      
            $viewImgs .= "</tr>"//$i=0;}
                   
            }
                     
            $counter++;
                     }
                    
                    
            $viewImgs .= "</table>
                       </td>
                      </tr>
                     </table>"
            ;
                   }
                  } 
            Last edited by Icheb; Tue 28 Dec '04, 6:29pm.

            Comment

            • HexOnxOnx
              Senior Member
              • Apr 2003
              • 638
              • 3.7.x

              #7
              That still displays the photos in one long column.
              http://www.icecreamforum.com

              Comment

              • Icheb
                Senior Member
                • Nov 2002
                • 1291

                #8
                I corrected a small mistake in the above code. Please try again.

                Comment

                • HexOnxOnx
                  Senior Member
                  • Apr 2003
                  • 638
                  • 3.7.x

                  #9
                  Originally posted by Icheb
                  I corrected a small mistake in the above code. Please try again.
                  That worked!!! Thanks very much for the help and for being patient!
                  http://www.icecreamforum.com

                  Comment

                  widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                  Working...