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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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