Jump to content

Tables and While?


unidox

Recommended Posts

I am having some trouble. I am trying to make a gallery that shows the images 5 acrosse, and unlimited down. So like:

 

Image Image Image Image Image

Image Image Image Image Image

Image Image

 

Like that. But I dont know how to use a while loop, the only way I use with while displays only 1 column. How do I do this? Thanks

Link to comment
Share on other sites

<table>
     <tr>
<?
$x=0;
while ($true) {
?>
          <td>Stuff Here</td>
<?
     if ($x%5) {
?>
     </tr><tr>
<?
     }

    $x++;

} // end while
?>
     </tr>
</table>

 

 

Haven't tested it but it should work

Link to comment
Share on other sites

Edit:  Beaten by 2 people....  Teach me to go afk lol.... 

Jabop, where is $true set?

Crayon, wouldn't that do 4 a row?

 

---------------------------------------------------

 

You want a table (well... easiest way to do it) with 5 images a row?

 

psuedo-code:

 


i = 0;
c = number of rows
if(c > 0) {
   open table
   open row
   while(you have results from database) {
       if(i % 5 == 0) {
           close row
           open row
       }    
       put table td
}

if(c % 5) {
   //the last row didn't finish.... if that makes sense
   offset = 5 - c % 5;
   for(i = 0; i < c; ++i) {
       output an empty <td></td>
   }

}

close row
close table

}

Link to comment
Share on other sites

well my code didn't actually have tables added into it I was just showing you how to move to another row.  Jabop's code shows you that though. Basically you open the table and first row before the loop. Inside the loop, if condition is true, you close the previous row and open a new row.  Once the loop is done, you simply close the last row and table.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.