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? Quote Link to comment 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"; Quote Link to comment 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?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.