I need to create a script that contains an html table, help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

I need to create a script that contains an html table, help!

Post by canadian_angel »

I need to create a script with a function that accepts four string variables and returns a string that contains an HTML table element, enclosing each of the variables in its own cell, and I am new at php, help!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I need to create a script that contains an html table, h

Post by AbraCadaver »

This is extremely basic, so it would be nice if you took a try at it and requested help with code that is not working.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

Re: I need to create a script that contains an html table, h

Post by canadian_angel »

It may be pretty basic but as I said I am just learning, srry
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I need to create a script that contains an html table, h

Post by AbraCadaver »

canadian_angel wrote:It may be pretty basic but as I said I am just learning, srry
Can you at least post the code for a function that accepts four strings? If not, start here and we'll work through it: http://us.php.net/manual/en/functions.user-defined.php
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

Re: I need to create a script that contains an html table, h

Post by canadian_angel »

Code: Select all

<!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>Four Cell Table</title>
 </head>
    <body>
        <?php // Script 10.6 - create-four-cell-table.php

         // Address error handling.
        ini_set ('display_errors', 1);
        error_reporting (E_ALL & ~E_NOTICE);

        // This function accepts four variables.
       function accept make_four_variables ($four_cell_table + $hello + a_number + $another_Number) {
        $four_cell_table;
        $hello = "Hello World!";
        $a_number = 4;
        $another_Number = 8;
         return $four_cell_table; // Create four cell table
?>
       
    </body>
</html>
Last edited by Benjamin on Tue Jun 22, 2010 1:42 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I need to create a script that contains an html table, h

Post by AbraCadaver »

I'm trying to help you learn here rather than just giving you the code. Your function line doesn't look anything like what is in the manual. Did you read it? Aslo, you have created some HTML so it seems like you know it somewhat, but you haven't created the table or table cells.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

Re: I need to put this is a table!

Post by canadian_angel »

Code: Select all

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

         // Address error handling.
        ini_set ('display_errors', 1);
        error_reporting (E_ALL & ~E_NOTICE);


function maketea($type = "Tea")
{
    return "Making a cup of $type.\n";
}
echo maketea("Chinese Fruit Tea");

echo maketea("Mexican White Tea");

echo maketea("Japanese Green Tea");
?>
        
    </body>
</html>
Last edited by Benjamin on Tue Jun 22, 2010 1:43 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I need to create a script that contains an html table, h

Post by AbraCadaver »

What!?!?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

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

Post by canadian_angel »

I was told this displays properly but it is not in the form of a function, I am not sure what that means.




<!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
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>" . $row['Chinese Fruit Tea'] . "</td>";
echo "<td>" . $row['Mexican White Tea'] . "</td>";
echo "<td>" . $row['Japanese Green Tea'] . "</td>";
echo "<td>" . $row['British Camomille Tea'] . "</td>";
echo "</tr>";
}
echo "</table>";


?>
</body>
</html>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I need to create a script that contains an html table, h

Post by AbraCadaver »

O.K. so create a function that accepts 4 parameters and inside of it build another variable with your table as you have shown but use the 4 parameters instead of the $row variables. Then return this new variable.
Last edited by AbraCadaver on Wed Jun 23, 2010 4:20 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: I need to create a script that contains an html table, h

Post by ell0bo »

It means, most likely, pack your table cells into an array (bonus hint, it'll be a multi dimensional array). Then you just run through 2 for loops outputting the tr and td's and you're done.

you might want to look into the function 'count' for your for loop, however you could get away doing a foreach.

You will also need a if statement to toggle between th and td
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

Re: I need to create a script that contains an html table, h

Post by canadian_angel »

Sorry not sure how-otherwise I would.
Post Reply