![]() |
![]() |
![]() |
|
|
#1 (permalink) |
|
Huggles, sir?
Join Date: May 2003
Location: Seattle
|
[php] Arrays, Table Rows, etc
For a project that I am working on, I am going to need to dynamically create a table of $x amount of elements, and display them in an orderly fashion. For instance, in a table with 4-5 elements per row. The problem with this, is that if you have an array of 10 elements and you decide to split it up into rows of 4, you have two spaces left over which will break the table unless you fill them up with something.
I've devised a way to do this with any array, and it works pretty well, I think. It's a bit late, and I didn't get much sleep last night so I'm kind of fuzzy as to how well I am doing this, or how it could be done better. Below is the code. Click here to see it in action. PHP Code:
__________________
seretogis - sieg heil perfect little dream the kind that hurts the most, forgot how it feels well almost no one to blame always the same, open my eyes wake up in flames |
|
|
|
|
|
#2 (permalink) |
|
It's Just A Game
Join Date: Sep 2003
Location: San Francisco
|
Try printing " " instead of "empty"; it should just give you a blank table entry if that's what you really want.
Also, it's putting a blank table row at the bottom of the table, so changing PHP Code:
PHP Code:
__________________
The spice must flow... "My friends I will have an energy policy that we will be talking about, which will eliminate our dependence on oil from the Middle East that will – that will then prevent us – that will prevent us from having ever to send our young men and women into conflict again in the Middle East." --John McCain May 2nd 2008 Last edited by n0nsensical; 02-06-2004 at 10:02 PM. |
|
|
|
|
|
#3 (permalink) |
|
Tilted
Join Date: Apr 2003
Location: Tha Boro
|
I've got a function like that, wrote it a few years back when I was still learning php, so it's probably not as optimised as it could be.
It does allow you to set the number of columns you want and distributes the items accordingly (adding empty cells if the final row isn't long enough) It was originally designed for displaying a table of links, hence the m_items variable is a hash of url=name&... PHP Code:
__________________
I try to take life one day at a time, but sometimes several days attack me at once. |
|
|
|
![]() |
| Bookmarks |
| Tags |
| arrays, php, rows, table |
| Thread Tools | |
|
|