Jump to content

Math problem


env3rt

Recommended Posts

There is probably a realy simple solution to this but I can't find it :P

 

I need the $num1 to go up each time instead of switching to the number I put it to.

<? 
$num1 = 0;
$result = Rand (1,6); 

if ($result ==1) 
{ 
Echo "1";
$num1 += 1;
} 

if ($result ==2) 
{ 
Echo "2"; 
$num1 += 2;
} 

if ($result ==3) 
{ 
Echo "3"; 
$num1 += 3;
} 

if ($result ==4) 
{ 
Echo "4"; 
$num1 += 4;
} 

if ($result ==5) 
{ 
Echo "5"; 
$num1 += 5;
} 

if ($result ==6) 
{ 
Echo "6"; 
$num1 += 6;
}
}
echo "<br>".$num1;
?>

 

Post if you don't understand problem or you can help.

Link to comment
https://forums.phpfreaks.com/topic/73032-math-problem/
Share on other sites

<?php
include ("num.php");
If ($question) 
{
$result = Rand (1,6);
$num1 = $num1 + $result;

if ($result ==1) 
{ 
Echo "1";
}

if ($result ==2) 
{ 
Echo "2"; 
} 

if ($result ==3) 
{ 
Echo "3"; 
} 

if ($result ==4) 
{ 
Echo "4"; 
} 

if ($result ==5) 
{ 
Echo "5"; 
} 

if ($result ==6) 
{ 
Echo "6"; 
}
}
echo "<br>".$num1;
?> 

 

Inside num.php is $num1 = 0; so it wont reset each time but it's still not working

Link to comment
https://forums.phpfreaks.com/topic/73032-math-problem/#findComment-368360
Share on other sites

why won't it reset ?

because its in another from.. but your including that file....

 

if your trying to keep the value and just increase it everytime its run.. then your need to store the number in a session, cookie, database or file.., then read it back in, if the session (whatever you used) doesn't exist then create it and the num will start at 0 or 1

Link to comment
https://forums.phpfreaks.com/topic/73032-math-problem/#findComment-368366
Share on other sites

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.