kle_3187 Posted November 8, 2008 Share Posted November 8, 2008 Hi everyone! Please help me as im totally lost! I need to make a table where the user can select the ammount of rows and columns so what Ive done so far is make a table with drop down boxes where the user can select the rows and columns but I don't know how to ransfer this? Can anyone please help? <table colour = " red " border = " 1 "> <caption> <strong>Please Select...</strong></caption> <thead> <tr> <th> No. of Rows </th> <th> No. of Columns </th> </tr> </thead> <tfoot> <tr> <th> Total </th> <th> Rows+Columns </th> </tr> </tfoot> <tbody> <tr> <td> <select> <option value"1R">1 Row</option> <option value"2R">2 Rows</option> <option value"3R">3 Rows</option> </select> </td> <td> <select> <option value"1C">1 Column</option> <option value"2C">2 Columns</option> <option value"3C">3 Columns</option> </select></td> </tr> </tbody> </table> Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/ Share on other sites More sharing options...
Barand Posted November 8, 2008 Share Posted November 8, 2008 Familiarise yourself with HTML forms http://www.w3schools.com/html/html_forms.asp Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685658 Share on other sites More sharing options...
kle_3187 Posted November 8, 2008 Author Share Posted November 8, 2008 Thanks for the link. The HTML isnt really the problem its how to code this in PHP I am having difficulty in. Can anyone advise on what i need to write on the server or point me in the direction of some sample code? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685685 Share on other sites More sharing options...
DeanWhitehouse Posted November 8, 2008 Share Posted November 8, 2008 tizag.com w3schools.com Look at there php tutorials on form processing. Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685688 Share on other sites More sharing options...
Barand Posted November 8, 2008 Share Posted November 8, 2008 Thanks for the link. The HTML isnt really the problem its how to code this in PHP I am having difficulty in. You don't show any <form> tags Your <select>s don't have name attributes You use PHP to output HTML code, but if you don't know the correct HTML, how do hope to get it right with PHP Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685701 Share on other sites More sharing options...
kle_3187 Posted November 8, 2008 Author Share Posted November 8, 2008 Well that was taken straight from my lecture notes which I assumed to be correct. Thanks for the observation! Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685708 Share on other sites More sharing options...
DeanWhitehouse Posted November 8, 2008 Share Posted November 8, 2008 Another copy and paste basically, i thought you said the HTML isn't a problem, if you don't it then it is. ? Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685710 Share on other sites More sharing options...
kle_3187 Posted November 8, 2008 Author Share Posted November 8, 2008 No the PHP is the problem. It is my entention to write a more complex table as that only has 3 rows and columns but I merely wanted to gain an understanding in how to go about coding the PHP based on an easy table so I can apply the same principles to my own table Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685744 Share on other sites More sharing options...
DeanWhitehouse Posted November 9, 2008 Share Posted November 9, 2008 Go to the sites i mentioned then? Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685754 Share on other sites More sharing options...
Barand Posted November 9, 2008 Share Posted November 9, 2008 No the PHP is the problem. It is my entention to write a more complex table as that only has 3 rows and columns but I merely wanted to gain an understanding in how to go about coding the PHP based on an easy table so I can apply the same principles to my own table There is no way you can do anything in PHP from the HTML in your original post. I gave my reasons in my last post. Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-685755 Share on other sites More sharing options...
tryingtolearn Posted November 9, 2008 Share Posted November 9, 2008 I use a form that takes the # columns # of rows Border Width Cellpadding Cellspacing and Table width The php part then takes those inputs and creates the table using this, print "<table border=\"$border\" cellpadding=\"$cp\" cellspacing=\"$cs\" width=\"$width$ms\">\n"; for ($r=0; $r<$row; $r++) { print "<tr>\n"; if($r != $row) { for ($i=0; $i<$col; $i++) { $cell = $i+1; print "<td>$cell</td>\n"; } if($i == $col) { print "</tr>\n"; } } } print "</table>\n"; Here is the whole shabang that you can taylor to your needs. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Dyna Table</title> <style type="text/css"> html,body{margin:0;padding:0} body{font: 76% arial,sans-serif;text-align:center} p{margin:0 10px 10px} a{display:block;color: #981793;padding:10px} div#header h1{height:80px;line-height:50px;margin:0; padding-left:10px;background: #cccccc;color: #202020} div#container{text-align:left; border: 3px solid #202020;} div#content p{line-height:1.4} div#navigation{background:#404040; color: #cccccc;} div#extra{background:#cccccc; color: #404040; border-bottom: 1px solid #202020;} div#footer{background: #cccccc;color: #404040} div#footer p{margin:0;padding:5px 10px} div#container{width:700px;margin:0 auto} div#content{float:left;width:500px} div#navigation{float:right;width:200px} div#extra{clear:both;width:100%} </style> </head> <body> <div id="container"> <div id="header"><h1>Dynamic Table Creation</h1></div> <div id="wrapper"> <div id="content"> <p> <?php if (isset($_POST['submitted'])) { // Handle the form. // Check for Columns. if (!empty($_POST['columns'])) { $col = $_POST['columns']; } else { $col = FALSE; echo '<p><font color="red" size="+1">Please enter the amount of columns you need!</font></p>'; } // Check for Rows. if (!empty($_POST['rows'])) { $row = $_POST['rows']; } else { $row = FALSE; echo '<p><font color="red" size="+1">Please enter the amount of rows you need!</font></p>'; } // Check for border width. if (!empty($_POST['border'])) { $border = $_POST['border']; } else { $border = 0; } // Check for table width. if (!empty($_POST['width'])) { $width = $_POST['width']; } else { $width = 100; } // Check for cell Padding. if (!empty($_POST['cp'])) { $cp = $_POST['cp']; } else { $cp = 0; } // Check for cell Spacing. if (!empty($_POST['cs'])) { $cs = $_POST['cs']; } else { $cs = 0; } // Check for cell Spacing. if ($_POST['meas'] == "perc") { $ms = "%"; } else { $ms = ""; } if ($col && $row) { print "<table border=\"$border\" cellpadding=\"$cp\" cellspacing=\"$cs\" width=\"$width$ms\">\n"; for ($r=0; $r<$row; $r++) { print "<tr>\n"; if($r != $row) { for ($i=0; $i<$col; $i++) { $cell = $i+1; print "<td>$cell</td>\n"; } if($i == $col) { print "</tr>\n"; } } } print "</table>\n"; echo"<textarea name=\"code\" rows=\"15\" cols=\"50\" >"; print "<table border=\"$border\" cellpadding=\"$cp\" cellspacing=\"$cs\" width=\"$width$ms\">\n"; for ($r=0; $r<$row; $r++) { print "<tr>\n"; if($r != $row) { for ($i=0; $i<$col; $i++) { print "<td></td>\n"; } if($i == $col) { print "</tr>\n"; } } } print "</table>\n"; echo"</textarea>"; } } ?> </p> </div> </div> <div id="navigation"> <p><strong>Set your table settings in the form inputs</strong> listed below. </p> </div> <div id="extra"> <p><strong>Table Settings</strong> <br /> <form action="index.php" method="post"> <p><b># of Columns:</b><br /> <input type="text" name="columns" size="15" maxlength="15" value="<?php if (isset($_POST['columns'])) echo $_POST['columns']; ?>" /></p> <p><b># of Rows:</b><br /> <input type="text" name="rows" size="15" maxlength="15" value="<?php if (isset($_POST['rows'])) echo $_POST['rows']; ?>" /> </p> <p><b>Border Width:</b><br /> <input type="text" name="border" size="15" maxlength="15" value="<?php if (isset($_POST['border'])) echo $_POST['border']; ?>" /> </p> <p><b>Cell Padding:</b><br /> <input type="text" name="cp" size="15" maxlength="15" value="<?php if (isset($_POST['cp'])) echo $_POST['cp']; ?>" /></p> <p><b>Cell Spacing:</b><br /> <input type="text" name="cs" size="15" maxlength="15" value="<?php if (isset($_POST['cs'])) echo $_POST['cs']; ?>" /> </p> <p><b>Table Width:</b><br /> <input type="text" name="width" size="15" maxlength="15" value="<?php if (isset($_POST['width'])) echo $_POST['width']; ?>" /> % <input name="meas" type="radio" value="perc"> or PX <input name="meas" type="radio" value="pix"></p> <div align="left"><input type="submit" name="submit" value="Create" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </p> </div> <div id="footer"><p>Sample Code Only</p></div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/131960-php-tables/#findComment-686279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.