MDanz Posted April 8, 2010 Share Posted April 8, 2010 how can i assign the number of columns and rows to a table depending on a variable? This variable will be random number so i can't just use if statements and alot of <td></td>, when the range of the variable is between 1-200. e.g. if($v=2) { \\display table columns and rows } i don't want to type a whole lot of <td></td> and <tr></tr> for each if statement. Is there a way around this, like with text area cols and rows? Link to comment https://forums.phpfreaks.com/topic/197955-table-help/ Share on other sites More sharing options...
MatthewJ Posted April 8, 2010 Share Posted April 8, 2010 Loops are your friend... echo "<table>\n"; for($i=1;$i<=$rows;$i++) { echo "<tr>\n"; for($j=1;$j<=$cols;$j++) { echo "<td></td>\n"; } echo "</tr>\n"; } echo "</table>\n"; Link to comment https://forums.phpfreaks.com/topic/197955-table-help/#findComment-1038751 Share on other sites More sharing options...
mapleleaf Posted April 8, 2010 Share Posted April 8, 2010 if($v=2) { while($i < $v) { //your <td> code and whatever content \\display table columns and rows } } I am still wondering why one might do this as presumably the content of the tables isn't random too?? Link to comment https://forums.phpfreaks.com/topic/197955-table-help/#findComment-1038752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.