Jump to content

[SOLVED] Math Problem and Coding Problem! NEED HELP!


yakoup46

Recommended Posts

I have been messing around with php and i have a pretty solid, pointless but solid, script but I have a bit of a problem. Here is the script:

<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)
echo $i . $even_number ."<br />";
else
if($i%5==0)
echo $i . $divis_5 . "<br />";
else
if($i%5==0 && $i%2==0)
echo $i . $divis_2_5 . "<br />";
else
echo $i . "<br />";
$i++;
}
?>
</body>
</html>

The first two if statements work. So like 4 displays $even_number, and 5 displays $divis_5, but I want it to display $divis_5_2 for numbers like 10 and 20. but it instead it displays $divis_5.

Any help would be awesome.

Thank You

Then move that conditional up before the other one that checks if $i is divisible by 5. You'll never get to $i%5==0 && $i%2==0 because it'll only evaluate to true if $i%5==0, but if that's true then it'll never be evaluated because it's only evaluated if it's not the case that $i%5==0

Well, imagine this set of conditionals (pseudo-code):

 

if A:
something;
else if B:
something else;
else:
something entirely different;

 

This is essentially saying:

 

If it's the case that A then do this: <something>

If it's not the case that A, but it's the case that B, then do this: <something else>

If it's not the case that B, then do this: <something entirely different>

 

B will only be evaluated if A is false.

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.