Jump to content


Photo

Table code problem


  • Please log in to reply
2 replies to this topic

#1 Moesian

Moesian
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 October 2006 - 08:35 AM

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

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

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

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 29 October 2006 - 08:54 AM

you made some typos.

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

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 Moesian

Moesian
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 October 2006 - 09:02 AM

Thanks alot, thought I checked it over properly, sorry to waste your time




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users