HoTDaWg Posted December 27, 2008 Share Posted December 27, 2008 hi there, im creating a simple for loop statement with a simple form to go along with it. here is my script: <?php print<<<HTML <html> <head> <title>Activity Two- inc to start and stop counting as well increment to increase by</title> </head> <body> <form method="post"> <input type = "text" name = "startint" value="start integer"><br> <input type = "text" name = "stopint" value="stop integer"><br> <input type = "text" name = "incr" value="increment to increase by"><br> <input type = "submit"> </form> HTML; if (isset($_POST['startint']) && isset($_POST['stopint']) && isset($_POST['incr'])) { $startint = $_POST['startint']; $stopint = $_POST['stopint']; $incr = $_POST['incr']; #this didnt work either settype($incr,"integer"); for($i = &$startint; $i <= $stopint; $i + $incr) { print "<br>". $i; } } ?> the issue is that it just echos the number 10 repeatedly. why is it that if i set the increment to $i ++ it works but not when i set the increment to anything other than one? any help would be greatly apprecaited thanks. Link to comment https://forums.phpfreaks.com/topic/138531-solved-for-loops-with-increment-other-than-one/ Share on other sites More sharing options...
kenrbnsn Posted December 27, 2008 Share Posted December 27, 2008 Do: <?php for($i = $startint; $i <= $stopint; $i += $incr) ?> Ken Link to comment https://forums.phpfreaks.com/topic/138531-solved-for-loops-with-increment-other-than-one/#findComment-724320 Share on other sites More sharing options...
HoTDaWg Posted December 27, 2008 Author Share Posted December 27, 2008 argh i should have known better; i gotta read my books more carefully thanks very much for your help! Link to comment https://forums.phpfreaks.com/topic/138531-solved-for-loops-with-increment-other-than-one/#findComment-724323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.