Page 1 of 1
I need to create a script that contains an html table, help!
Posted: Mon Jun 21, 2010 8:24 pm
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!
Re: I need to create a script that contains an html table, h
Posted: Mon Jun 21, 2010 9:20 pm
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.
Re: I need to create a script that contains an html table, h
Posted: Mon Jun 21, 2010 9:43 pm
by canadian_angel
It may be pretty basic but as I said I am just learning, srry
Re: I need to create a script that contains an html table, h
Posted: Tue Jun 22, 2010 9:55 am
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
Re: I need to create a script that contains an html table, h
Posted: Tue Jun 22, 2010 10:17 am
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>
Re: I need to create a script that contains an html table, h
Posted: Tue Jun 22, 2010 12:19 pm
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.
Re: I need to put this is a table!
Posted: Tue Jun 22, 2010 1:08 pm
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>
Re: I need to create a script that contains an html table, h
Posted: Tue Jun 22, 2010 1:24 pm
by AbraCadaver
What!?!?
Re: I need to put this in the form of a function, help!
Posted: Wed Jun 23, 2010 2:48 pm
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>
Re: I need to create a script that contains an html table, h
Posted: Wed Jun 23, 2010 4:19 pm
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.
Re: I need to create a script that contains an html table, h
Posted: Wed Jun 23, 2010 4:19 pm
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
Re: I need to create a script that contains an html table, h
Posted: Wed Jun 23, 2010 4:46 pm
by canadian_angel
Sorry not sure how-otherwise I would.