Jump to content

table inside a table


malikah

Recommended Posts

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?

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

@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....

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.