02-06-2004, 08:53 PM | #1 (permalink) |
Huggles, sir?
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 |
02-06-2004, 08:56 PM | #2 (permalink) |
Junkie
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:
__________________
"Prohibition will work great injury to the cause of temperance. It is a species of intemperance within itself, for it goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation, and makes a crime out of things that are not crimes. A Prohibition law strikes a blow at the very principles upon which our government was founded." --Abraham Lincoln Last edited by n0nsensical; 02-06-2004 at 09:02 PM.. |
02-07-2004, 05:31 AM | #3 (permalink) |
Tilted
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. |
Tags |
arrays, php, rows, table |
|
|