Jump to content

Table code problem


Moesian

Recommended Posts

Hi,

Im just working though a tutorial book and have stumbled across a bit of  a problem whe i use the following code to create a table

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if (!$_POST['submit'])
{
?>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
Enter number of rows
<input name="rows" type="text" size="4">
and columns
<input name="columns" type="text" size="4">
<input type="submit" name="submit" value="Draw Table">
</form>
<?php
}
else
{
?>
<table border="1" cellspacing="5" cellpadding="0">
<?php
//set variables from form input
$rows = $_POST['rows'];
$columns = $_POST ['columns'];

//loop to create rows
for ($r = 1; $r <= £rows; $r++)
{
echo "<tr>";
//loop to crearte columns
for ($c = 1; $c <= $columns; $c++)
{
echo "<td>$nbsp;</tb>\n";
}
echo "</tr>\n";
}
?>
</table>
<?php
}
?>

</body>
</html>
[/code]

I cant figure out why it doesnt work, the first page works where you can enter the table size but it just doesnt draw the table. Im using
Apache 2.0.59  with PHP 5.1.6. I hope someone can point me in the right direction this one puzzles me.

Thanks
Link to comment
https://forums.phpfreaks.com/topic/25462-table-code-problem/
Share on other sites

you made some typos.

[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if (!$_POST['submit'])
{
?>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
Enter number of rows
<input name="rows" type="text" size="4">
and columns
<input name="columns" type="text" size="4">
<input type="submit" name="submit" value="Draw Table">
</form>
<?php
}
else
{
?>
<table border="1" cellspacing="5" cellpadding="0">
<?php
//set variables from form input
$rows = $_POST['rows'];
$columns = $_POST['columns'];

//loop to create rows
for ($r = 1; $r <= $rows; $r++)
{
echo "<tr>";
//loop to crearte columns
for ($c = 1; $c <= $columns; $c++)
{
echo "<td>&nbsp;</td>\n";
}
echo "</tr>\n";
}
?>
</table>
<?php
}
?>

</body>
</html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/25462-table-code-problem/#findComment-116189
Share on other sites

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.