malikah Posted December 8, 2007 Share Posted December 8, 2007 Hi, whats the easiest way to put a table inside a table. I'm using this for a calendar which changes dynamically depending on the year/month. I've already acheived putting the months inside a table and they cascade vertically down the page, but now I want each one of those month's tables to spread 4x3 on the page. Unfortunately, echoing new tables inside of a <td> tag means that I can't use "" quotes any more. Any suggestions? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 8, 2007 Share Posted December 8, 2007 I think you'll find you can use double quotes if you really want to - just a case of making a couple changes to adapt. Not exactly sure what problem it is you're asking for help with... What would the second table contain? When would it appear? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 I think you can do what you want without a new table. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 8, 2007 Share Posted December 8, 2007 I think you can do what you want without a new table. Depends how much information is to be displayed in the cell and how [complex] it is to be formatted. EDIT: Just noticed - my 1,000th post! Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 I would still do it without a table. People try to use tables for formatting when it makes more sense to use CSS. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 you can still echo a table inside a table - just escape quotes or use a single quote. example of double quotes: <?php echo "<table witdh=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n"; echo "<td witdh=\"100%\" height=\"100%\">\n"; echo "<table witdh=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n" echo "<tr>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "<td witdh=\"25%\" height=\"33%\">\n"; // content here echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; echo "</td>\n"; echo "</table>\n"; ?> example of single quotes: [code] <?php echo "<table witdh='100%' height='100%' cellpadding='0' cellspacing='0'>\n"; echo "<td witdh='100%' height='100%'>\n"; echo "<table witdh='100%' height='100%' cellpadding='0' cellspacing='0'>\n"; echo "<tr>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "<td witdh='25%' height='33%'>\n"; // content here echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; echo "</td>\n"; echo "</table>\n"; ?> [/code] Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 8, 2007 Share Posted December 8, 2007 I don't want to get into a debate about whether to use CSS or tables for formatting, especially in someone else's topic - revraz, PM me if you're interested in a chat about it - I'm interested in your views on it if you use CSS for formatting. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 9, 2007 Share Posted December 9, 2007 @phpquestioner echoing that amount of html makes it very difficult to maintain - if you are using mcv methods then that situation would never occur. Alternatively (IMO of course) it is far better to break out of php for html and simply echo bits that are needed.. As to the OP you can use double quotes (indeed you should) - if you are doing this in a string simple use single quotes for the string - better stil break out of php to do it.... Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 9, 2007 Share Posted December 9, 2007 @phpquestioner echoing that amount of html makes it very difficult to maintain - if you are using mcv methods then that situation would never occur. Alternatively (IMO of course) it is far better to break out of php for html and simply echo bits that are needed.. As to the OP you can use double quotes (indeed you should) - if you are doing this in a string simple use single quotes for the string - better stil break out of php to do it.... That is framework right - I do not design my PHP with OOP framework. PHP designers also use author comments as well; for the same purpose HTML comments are used - so it's not very difficult to maintain. Quote Link to comment Share on other sites More sharing options...
malikah Posted December 9, 2007 Author Share Posted December 9, 2007 Ok, here's the code (copy & pastable): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> .td_empty{ width:40px; height:40px; border-style:solid; border-width:2px; border-color:#CCCC99; text-align:left; font-family:Arial, Helvetica, sans-serif; font-size:12px; } .td_full{ width:40px; height:40px; border-style:solid; border-width:2px; border-color:#CC9900; background-color:#CCCC99; text-align:left; font-family:Arial, Helvetica, sans-serif; font-size:12px; } </style> </head> <body> <?php //-----2008-----// $jan = array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0); $feb = array(0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,0); $mar = array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0); $apr = array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0); $may = array(0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31); $jun = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0); $jul = array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0); $aug = array(0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0); $sep = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0); $oct = array(0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0); $nov = array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0); $dec = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0); $month = array($jan,$feb,$mar,$apr,$may,$jun,$jul,$aug,$sep,$oct,$nov,$dec); $monthPlus =- 1; echo "<table>"; for ($s=1;$s<=3;$s++){ echo "<tr>"; for ($a=1;$a<=4;$a++){ echo "<td>"; for($yr=1; $yr<=count($month); $yr++){ $monthPlus++; $dayPlus =- 1; echo "<table>"; for($i=1;$i<=count($month[$monthPlus])/7;$i++){ echo "<tr valign=top>"; for($f=1;$f<=7;$f++){ $dayPlus++; $show = $month[$monthPlus][$dayPlus]; if($show==0){ $show=" "; echo "<td class='td_empty'>$show</td>"; }//end if $show else{ echo "<td class='td_full'>$show</td>"; }//end else }//end for $f echo "</tr>"; }//end for $i echo "</table>"; }//end for $yr echo "</td>"; }//end for $a echo "</tr>"; }//end for $s echo "</table>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
anatak Posted December 10, 2007 Share Posted December 10, 2007 you can also use echo '<table><tr><td width="45"></td></tr></table>'; It is something I do sometimes when I have html to echo I wonder if there is a drawback about using singles quotes to echo your statements. Please note that with single quotes your variables have to be outside the echo example $text_var='and some more text'; echo 'some text'.$text_var; will output some textand some more text echo "some text $text_var"; will output some text and some more text echo 'some text $text_var'; will output some text $text_var I hope it will help you to malikah very interesting will take a look at it too thanks for posting this Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 12, 2007 Share Posted December 12, 2007 You could also use: echo <<<HTML You can use "double quotes" and 'single quotes' here, along with displaying $variables. HTML; 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.