Jump to content

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


silverglade

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>

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.