Jump to content

looping please


chriscloyd

Recommended Posts

okay heres what i want this code i did to do
on the case page
i would type 2 into the textbox
then it would send it ot the cash_action case
and for every turn i want it to do the while loop
so since i entered 2 i want it to to do two
[code]<?php
switch($_GET['page']){
case "cashme":
echo '<form name="form1" method="post" action="?page=cash_action">
  <label>How many turns do you wanna spend on cash?
  <input name="turns" type="text" id="turns">
  </label>
  <br>
  <label>
  <input type="submit" name="Submit" value="Show me the money">
  </label>
</form>';
break;
case "cash_action":
//use turn
$email = $_SESSION['firefight'];
$userinfo = mysql_query("SELECT * FROM users WHERE email = '$email'");
$info = mysql_fetch_assoc($userinfo);
$set_population = $info['population'];
$set_cash = $info['cash'];
$set_turns = $info['turns'];
$set_food = $info['food'];
$set_metal = $info['metal'];
$set_lt = $info['lt'];
$set_turrets = $info['turrets'];
$set_nukes = $info['nukes'];
$turnscash = $_POST['turns'];
while($turnscash) {
$timesc = rand(100,5000);
$new_money = .15 * $timesc;
$cash = $set_cash + $newmoney;
$timesp = rand(0,100);
$population = $set_population + $timesp;
$foodused = .023 * $set_population;
$food_produced = rand($foodused,$set_food);
$food = $set_food - $foodused + $food_produced;
$turns = $set_turns - $turnscash;
$units = .80 * $population;
$nukes = .05 * $units;
$lt = .45 * $units;
$turrets = .30 * $units;
$metal = rand(100,5000);
echo '<table width="430" border="0" cellspacing="3" cellpadding="0">
  <tr>
    <td width="241">Population Produced: <span class="green">+'.$population.'</span></td>
    <td width="230"><div align="center">From the increase of your population you recieved </div></td>
  </tr>
  <tr>
    <td>Cash Produced: <span class="green">+'.$cash.'</span></td>
    <td>Light Armor Units: <span class="green">+'.$lt.'</span></td>
  </tr>
  <tr>
    <td>Metal Produced: <span class="green">+'.$metal.'</span></td>
    <td>Turrets: <span class="green">+'.$turrets.'</span></td>
  </tr>
  <tr>
    <td>Turns: -1 </td>
    <td>Nukes: <span class="green">+'.$nukes.'</span></td>
  </tr>
  <tr>
    <td>Food Used: <span class="red">-'.$foodused.'</span></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Food Produced: <span class="green">+'.$food_produced.'</span></td>
    <td>&nbsp;</td>
  </tr>
</table>';
mysql_query("UPDATE users SET food = '$food', cash = $cash, population = '$population',turns = '$turns', metal = '$metal', lt = '$lt', nukes = '$nukes', turrets = '$turrets' WHERE email = '$email'");
}
break;
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/29503-looping-please/
Share on other sites

okay i got my loop to work
heres the code but it wont update the query everytime
[CODE]
$email = $_SESSION['firefight'];
$userinfo = mysql_query("SELECT * FROM users WHERE email = '$email'");
$info = mysql_fetch_assoc($userinfo);
$set_population = $info['population'];
$set_cash = $info['cash'];
$set_turns = $info['turns'];
$set_food = $info['food'];
$set_metal = $info['metal'];
$set_lt = $info['lt'];
$set_turrets = $info['turrets'];
$set_nukes = $info['nukes'];
$turnscash = $_POST['turns'];
for ($i = 0; $i < $turnscash; $i++)
{
$timesc = rand(100,5000);
$new_moneys = .15 * $timesc;
$new_money = floor($new_moneys);
$cash = $set_cash + $newmoney;
$timesp = rand(0,100);
$population = $set_population + $timesp;
$fooduseds = .023 * $set_population;
$foodused = floor($fooduseds);
$food_produced = rand($foodused,$set_food);
$food = $set_food - $foodused + $food_produced;
$turns = $set_turns - $turnscash;
$units = .80 * $population;
$unit = floor($unites);
$nukes = .05 * $units;
$nuke = floor($nukes);
$lts = .45 * $units;
$lt = floor($lts);
$turretss = .30 * $units;
$turrets = floor($turretss);
$metals = rand(100,5000);
$metal = $set_metal + $metals;
echo '<table width="430" border="0" cellspacing="3" cellpadding="0">
  <tr>
    <td width="241">Population Produced: <span class="green">+'.$population.'</span></td>
    <td width="230"><div align="center">From the increase of your population you recieved </div></td>
  </tr>
  <tr>
    <td>Cash Produced: <span class="green">+'.$cash.'</span></td>
    <td>Light Armor Units: <span class="green">+'.$lt.'</span></td>
  </tr>
  <tr>
    <td>Metal Produced: <span class="green">+'.$metal.'</span></td>
    <td>Turrets: <span class="green">+'.$turrets.'</span></td>
  </tr>
  <tr>
    <td>Turns: -1 </td>
    <td>Nukes: <span class="green">+'.$nukes.'</span></td>
  </tr>
  <tr>
    <td>Food Used: <span class="red">-'.$foodused.'</span></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Food Produced: <span class="green">+'.$food_produced.'</span></td>
    <td>&nbsp;</td>
  </tr>
</table>';
mysql_query("UPDATE users SET food = '$food', cash = $cash, population = '$population',turns = '$turns', metal = '$metal', lt = '$lt', nukes = '$nukes', turrets = '$turrets' WHERE email = '$email'");
}
[/CODE]
Link to comment
https://forums.phpfreaks.com/topic/29503-looping-please/#findComment-135390
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.