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.

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

<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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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