Jump to content

Re: I need to put this in the form of a function, help!


canadian_angel

Recommended Posts

i am not sure if I have already posted this and if I have I am sorry, I need to put this in the form of  a function, I am trying but its not working.

 

 

 

 

<!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 a four cell table.

      function makefourcelltable ($table){

echo "<table border='2'>

<tr>

<th>Chinese Fruit Tea</th>

<th>Mexican White Tea</th>

<th>Japanese Green Tea</th>

<th>British Camomille Tea</th>

</tr>";

      }

  echo "<tr>";

  echo "<td>" . $table['Chinese Fruit Tea'] . "</td>";

  echo "<td>" . $table['Mexican White Tea'] . "</td>";

  echo "<td>" . $table['Japanese Green Tea'] . "</td>";

  echo "<td>" . $table['British Camomille Tea'] . "</td>";

  echo "</tr>";

echo "</table>";

 

?>

    </body>

</html>

 

First off, the string you are echoing :

 

echo "<table border='2'>
<tr>
<th>Chinese Fruit Tea</th>
<th>Mexican White Tea</th>
<th>Japanese Green Tea</th>
<th>British Camomille Tea</th>
</tr>"

 

Should not be encased with " ", they should be encased with ' ', since you are not evaluating the string.

 

Second, why are you creating that function? It doesn't seem to do anything, so why not just use html? If you need dynamic variables in the table, you can just use something like     

 

<td><?=$table1 ?></td>

 

Expand on what you're trying to do or give us a better example and we should be able to help you better.

The string:

<?php
echo "<table border='2'>
<tr>
<th>Chinese Fruit Tea</th>
<th>Mexican White Tea</th>
<th>Japanese Green Tea</th>
<th>British Camomille Tea</th>
</tr>"
?>

is enclosed in double quotes, since there are single quotes in it.  If the OP enclosed it in single quotes, the single quotes in the string would need to be replaces with double quotes.

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.