env3rt Posted October 13, 2007 Share Posted October 13, 2007 There is probably a realy simple solution to this but I can't find it 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 More sharing options...
MadTechie Posted October 13, 2007 Share Posted October 13, 2007 i don't get what your trying surely $num1 = $result; or to increase $num1 by 1 do $num1++; Link to comment https://forums.phpfreaks.com/topic/73032-math-problem/#findComment-368346 Share on other sites More sharing options...
env3rt Posted October 13, 2007 Author Share Posted October 13, 2007 Ok this is what I want: If the random number is five, I want it to add 5 to the total number, add 1 for 1, 2 for 2 etc.. Link to comment https://forums.phpfreaks.com/topic/73032-math-problem/#findComment-368349 Share on other sites More sharing options...
MadTechie Posted October 13, 2007 Share Posted October 13, 2007 so $num1 = ($num1*2); or $num1 = ($num1+$num1); i assum you know your always setting $num1 to 0 at the start! Link to comment https://forums.phpfreaks.com/topic/73032-math-problem/#findComment-368352 Share on other sites More sharing options...
AndyB Posted October 13, 2007 Share Posted October 13, 2007 Sounds like $num1 = $num1 + rand(1,6) would do nicely Link to comment https://forums.phpfreaks.com/topic/73032-math-problem/#findComment-368353 Share on other sites More sharing options...
env3rt Posted October 13, 2007 Author Share Posted October 13, 2007 <?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 More sharing options...
MadTechie Posted October 13, 2007 Share Posted October 13, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.