0
<!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>Teas of the World!</title>
    </head>
    <body>
       <?php // Script 10.6 - Teas of the World.php
       // This function displays a four cell table.
       function tea($types) {

       $types = array ("Chinese Green", "Japanese Red", "Korean Black", "British White");

       for ($cell = 0; $cell < 4; $cell++) { // Displays the cell count.
       echo "<td>".$types[$cell]."</td>";

       }

       }

       ?>

    </body>
</html>

Edited by Reverend Jim: Fixed formatting

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

1. You are using a td element without having a table or tr.
2. You have declared it as a function, and not very well at that, but you have not called the function so it will not do anything.
3. For scalability, it would be better to use a foreach rather than a for to output the columns.

Also, remember to use [code]

[/code] tags around your code, and finally, some text detailing what you have tried and what it is/is not doing would be better than just dumping your code here.

-1
<!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>Teas of the World!</title>
</head>
<body>
<table>

<?php // Script 10.6 - Teas of the World.php
// This function displays a four cell table.
function tea() {

	$types = array ("Chinese Green", "Japanese Red", "Korean Black", "British White");
	foreach($types as $val){
	echo "<tr><td>".$val."</td></tr>";
	}

}
tea();
?>

</table>
</body>
</html>
-1
<!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>Teas of the World!</title>
</head>
<body>
<?php 
$types = array ("Chinese Green", "Japanese Red", "Korean Black", "British White");

echo "<table border='1'>";
echo "<tr align='center'><td colspan='4'>Columns</td></tr>";
echo "<tr>";
for ($cell = 0; $cell < sizeof($types); $cell++) 
{ 
	echo "<td>".$types[$cell]."</td>";
}
echo"</tr></table>";
?>
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.