crossfuse Posted March 29, 2009 Share Posted March 29, 2009 http://cpsc.maconstate.edu/1010/chapter3/drivecube.php i'm trying to make a site like this for my php program but with a textbox instead where you can type in numbers...i know it includes this code: ------------------------------ for ( $i = 0; $i < $max; $i++ ) { Set of statements to repeat } and while ($ctr < $max) { Set of statements to repeat } ------------------ i'm a newb so if i could get some help i would appreciate it Link to comment https://forums.phpfreaks.com/topic/151670-for-loop-help/ Share on other sites More sharing options...
RichardRotterdam Posted March 30, 2009 Share Posted March 30, 2009 you just need one loop really and within that loop you can calculate the values of a square and cube for ( $i = 0; $i < $max; $i++ ) { $square=your_calculation_here; $cube=your_calculation_here; echo some_of_your_calculated_values_here; } Link to comment https://forums.phpfreaks.com/topic/151670-for-loop-help/#findComment-796669 Share on other sites More sharing options...
JasonLewis Posted March 30, 2009 Share Posted March 30, 2009 Well, if it's for text boxes, then you can do it like so: for($i = 0; $i < $max; ++$i){ echo "<input type='text' name='data[]' /><br />"; } Then after you submit it you'd need to loop through all the entries because it will be an array. Link to comment https://forums.phpfreaks.com/topic/151670-for-loop-help/#findComment-796701 Share on other sites More sharing options...
crossfuse Posted March 30, 2009 Author Share Posted March 30, 2009 ok that looks about, but something's still wrong...i get this error: Parse error: syntax error, unexpected T_FOR in /usr/local/www/cpsc/students/justin.ham/square.php on line 26 http://cpsc.maconstate.edu/students/justin.ham/square.html that's the website i have and here's the PHP code for receiving. <html> <body> <?php $number = $_POST["number"]; $number2 = (1) ; $sum = ($number + $number2) ; print("<br> The number plus 1 is $sum"); ?> <br><br> <font size="4" color="blue"> Table of Square Values</font><br> <table border= 1> <th> Number</th><th>Sqr </th> <?php $max=$number for($i = 0; $i < $max; ++$i){ echo "<input type='text' name='data[]' /><br />"; } ?> </body> </html> i really have no clue how to make this work... Link to comment https://forums.phpfreaks.com/topic/151670-for-loop-help/#findComment-797170 Share on other sites More sharing options...
JasonLewis Posted March 31, 2009 Share Posted March 31, 2009 Your missing a ; $max=$number Should be: $max=$number; Link to comment https://forums.phpfreaks.com/topic/151670-for-loop-help/#findComment-797558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.