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
https://forums.phpfreaks.com/topic/111910-tables-and-while/
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
https://forums.phpfreaks.com/topic/111910-tables-and-while/#findComment-574421
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
https://forums.phpfreaks.com/topic/111910-tables-and-while/#findComment-574435
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.