Jump to content

[SOLVED] I want PHP to count to the enterned number instead of $var++.


yakoup46

Recommended Posts

<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.

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?

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

 

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).

<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.

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>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.