xionhack Posted March 13, 2009 Share Posted March 13, 2009 Hello. I am making some tables that are generated from some values in a database. The is always 1 word in the top of the table (1st row) and then some values on the 2nd row. Some tables on the 2nd row have 3 columns, some 4, some 5, etc... How can I make the colspan value to be set automatically? Thanks! Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/ Share on other sites More sharing options...
Floydian Posted March 13, 2009 Share Posted March 13, 2009 Impossible to say without knowing what you're working with and how you get the numbers of rows. But it would involve finding out the maximum columns needed, then doing some math Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784200 Share on other sites More sharing options...
lonewolf217 Posted March 13, 2009 Share Posted March 13, 2009 are you looking to always have one large row at the top of each table spanning all columns ? Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784203 Share on other sites More sharing options...
kittrellbj Posted March 13, 2009 Share Posted March 13, 2009 You could do it by a series of isset's, empty's, or etc., depending on if it is an array or however you are doing it. <?php if (isset($variable1)) { echo "<TD COLSPAN=2>"; } else { echo "<TD>"; } ?> Depends on how complex the application is, really. I would look at my data organization, though, before proceeding. If you have lots of values that aren't really related to each other (they don't have the same information), it may be more efficient to separate them into separate tables and organize the data better in that way. I am not really sure what your data structure looks like, though. Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784207 Share on other sites More sharing options...
xionhack Posted March 14, 2009 Author Share Posted March 14, 2009 are you looking to always have one large row at the top of each table spanning all columns ? Yes, that's what Im looking for! Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784219 Share on other sites More sharing options...
Floydian Posted March 14, 2009 Share Posted March 14, 2009 instead of echoing the table rows out on each loop iteration, save them to a variable using concatenation then, at the end of the loop, you should know what the most columns would be then echo out the first row, then echo the variable you saved the other rows in Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784221 Share on other sites More sharing options...
lonewolf217 Posted March 14, 2009 Share Posted March 14, 2009 are you looking to always have one large row at the top of each table spanning all columns ? Yes, that's what Im looking for! you can either use a table header <th> for this, or you can set the colspan to some arbitrary high number (higher than the possible number of columns) and it will just resize for whatever table size is appropriate Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784223 Share on other sites More sharing options...
xionhack Posted March 14, 2009 Author Share Posted March 14, 2009 are you looking to always have one large row at the top of each table spanning all columns ? Yes, that's what Im looking for! you can either use a table header <th> for this, or you can set the colspan to some arbitrary high number (higher than the possible number of columns) and it will just resize for whatever table size is appropriate When I make it a <th>, how can I set it in the middle and for the rest of the cells to merge with that one? Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784256 Share on other sites More sharing options...
lonewolf217 Posted March 14, 2009 Share Posted March 14, 2009 okay now i think im confused about what the layout is exactly. perhaps some sort of diagram would help, or just write out in words what a typical table layout would be specifying exactly where you want the colspans to be Link to comment https://forums.phpfreaks.com/topic/149330-set-colspan/#findComment-784258 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.