yakoup46 Posted April 12, 2009 Share Posted April 12, 2009 <html> <title>File Test</title> <body> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> Enter Number <input type="text" name="number"> <input type="submit"> </form> <?php include("values.php"); $i = @$_POST['number']; if(empty($i)) echo "Enter Number Please"; else while($i<50) { if($i%2==0 && $i%5==0) echo $i . $divis_2_5 ."<br />"; else if($i%2==0) echo $i . $even_number . "<br />"; else if($i%5==0) echo $i . $divis_5 . "<br />"; else echo $i . "<br />"; $i++; } ?> </body> </html> In this script the entered number in the form is assigned a value based on the if statements. However, the script only works if $i is less than 50 (hence: $i<50). I want any value to be entered and the script will count up that number and assign the the variables according the if statements just as before. So basically I want the script to do the exact same thing except that I don't want a bound on the $i. Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/ Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 increment a separate variable instead of $i... $i = $_POST['number']; while ($x < 50) { //code here $x += $i; } Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808045 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 That only makes it so that when i enter a number it does that number only. I want it so that if i enter 4 it assigns the values(from the if statements) for 1, 2, 3, and 4. Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808048 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 can you give an example of what you want your code to look like or what you want the output to look like, if you enter in a specific number (like 4) Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808051 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 yeah just a min ill get it set up Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808055 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Pardon my intrusion, but like this possibly? <?php $i = $_POST['number']; for($ii = 0; $ii <= $i; $ii++) { //do your stuff. } ?> Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808056 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 Sorry Jack that didn't seem to help. :-\ Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808058 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 Okay Crayon: So there is a form, and in that form in the input box and when I press submit with the number 5 entered. The php goes through and starts from 1 and goes to 5. and for each number is assign a value. Like it assigns "big" for 5 and then "medium" for 3, so on and so forth. At this point my script will assign the values exactly this way except that I have to set the limit to a number like 50 and press 1 for it to count to 50 and assign the values. I want to be able to type 50 and have it count to 50. Get what i mean? Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808062 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 so..you just want it to count from 1 to $i instead of 1 to 50? $i = $_POST['number']; while ($x < $i) { //code here $x++; } Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808065 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Isn't that pretty much what I put..? ??? Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808070 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 okay lol. i am sure this is a problem on my end. So here is a very detailed description. [ 4 ]{Submit} 1 = small 2 = medium 3 = big 4 = large *that is what i want it to do. MINE DOES THIS [ 1 ]{Submit} |i have to put a bound like 4| 1 = small 2 = medium ect... I WANT THE FIRST WAY. i have the assigning values part down. I hope this helps Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808076 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 I don't understand. Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808078 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 Isn't that pretty much what I put..? ??? yes. But suggesting something in a different way sometimes helps. right...so you would want to count to the posted value. So unless there's something else you aren't mentioning, you would want to do the last thing I showed (or what jack showed). Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808080 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 <html> <title>File Test</title> <body> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> Enter Number <input type="text" name="number"> <input type="submit"> </form> <?php include("values.php"); $i = @$_POST['number']; if(empty($i)) echo "Enter Number Please"; else while($x < $i) { if($i%2==0 && $i%5==0) echo $i . $divis_2_5 ."<br />"; else if($i%2==0) echo $i . $even_number . "<br />"; else if($i%5==0) echo $i . $divis_5 . "<br />"; else echo $i . "<br />"; $x++; } ?> </body> </html> okay that is my script. if i enter 4. it display 4 big 4 big 4 big 4 big. Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808082 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 Okay well in the rest of your script that relied on $i being incremented before, you need to replace that with $x because that's the thing being incremented now. Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808085 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 so replace all my $i with $x except for "$i = @$_POST['number'];" when i do that i get a bunch of undefined variables Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808088 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 so...you did this? <html> <title>File Test</title> <body> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> Enter Number <input type="text" name="number"> <input type="submit"> </form> <?php include("values.php"); $i = @$_POST['number']; if(empty($i)) echo "Enter Number Please"; else while($x < $i) { if($i%2==0 && $i%5==0) echo $x . $divis_2_5 ."<br />"; else if($x%2==0) echo $x . $even_number . "<br />"; else if($x%5==0) echo $x . $divis_5 . "<br />"; else echo $x . "<br />"; $x++; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808090 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 I just set $x = 1 and that solved the problem. Thank you very much. But i was wondering how this works i can really comprehend it. I am sure its simple but i just can figure it out :-\. Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808093 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 $x is your counter. $i is what you want to count to. At the end of your while loop, $x is incremented by 1. Your while loop ($x < $i) executes until $x counts up to whatever $i is. Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808095 Share on other sites More sharing options...
yakoup46 Posted April 12, 2009 Author Share Posted April 12, 2009 Oh duh. lol thank you very much Link to comment https://forums.phpfreaks.com/topic/153754-solved-i-want-php-to-count-to-the-enterned-number-instead-of-var/#findComment-808097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.