Jump to content

[SOLVED] dynamic html table creation , cant get it to create the columns


Recommended Posts

hi, i cant get this php script to dynamically generate the columns in the table. any help greatly appreciated. thanks. derek

 

here is the html form

 

<!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=utf-8" />
<title>table_maker</title>
</head>

<body>

Please enter your desired table attributes.

<form action="table_maker.php" method="post">
Number of rows<input type="digit" name="rows" /><br />
Number of columns<input type="digit" name="columns" /><br />
Width as a percent <input type="digit" name="width" /><br />
Border 0 or 1 <input type="digit" name="border" /><br />
Color : red, blue, etc <input type="digit" name="color" /><br />

<input type="submit" />
<input type="reset">
</form>
</body>
</html>

 

and here is the table creator script

 

<?php


$width = $_POST['width'];                  //get variables from html file
$border = $_POST['border'];
$color = $_POST['color'];                 
$rows = $_POST['rows'];
$columns = $_POST['columns'];



function makeTable($rows,$width,$border,$color, $columns )
{

     ///youre altering the table dimensions with php!!!

$table .= "<table width=\"$width\" border=\"$border\" bgcolor=\"$color\">";



              
	for($i=0;$i<$rows;$i++) {

			$table .= " <tr> " ;	


	}




    for($i=0;$i<$columns;$i++) {


           $table .= " <td> text </td>";
        }


	for($i=0;$i<$rows;$i++) {

			$table .= "  </tr>";		
	}


	$table .= "</table>";

    
	return $table;
   

}


echo makeTable($rows, $width, $border, $color, $columns);       ///call to the great and powerful function table maker

?>
<!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=utf-8" />
<title>table_maker</title>
</head>

<body>


</body>
</html>

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.