silverglade Posted September 14, 2009 Share Posted September 14, 2009 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> Link to comment https://forums.phpfreaks.com/topic/174238-solved-dynamic-html-table-creation-cant-get-it-to-create-the-columns/ Share on other sites More sharing options...
mikesta707 Posted September 14, 2009 Share Posted September 14, 2009 try this for($i=0;$i<$rows;$i++) { $table .= " <tr> " ; for($i=0;$i<$columns;$i++) { $table .= " <td> text </td>"; } $table .="</tr>"; } Link to comment https://forums.phpfreaks.com/topic/174238-solved-dynamic-html-table-creation-cant-get-it-to-create-the-columns/#findComment-918509 Share on other sites More sharing options...
silverglade Posted September 14, 2009 Author Share Posted September 14, 2009 awesome mike!!!! i just had to replace the second i with j . but it worked ! thanks very much. Link to comment https://forums.phpfreaks.com/topic/174238-solved-dynamic-html-table-creation-cant-get-it-to-create-the-columns/#findComment-918559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.