<!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>

Recommended Answers

All 3 Replies

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.

<!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>
Member Avatar for rajarajan2017
<!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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.