![]() |
[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:
|
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:
|
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:
|
All times are GMT -8. The time now is 01:30 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project