cdoyle Posted December 6, 2009 Share Posted December 6, 2009 Hi, I need some help with a piece of code I'm writing. What this is suppose to do, is give the player a bonus for the upgraded addons they've installed to their car. So if player 1 has several addons that give an acceleration bonus, it suppose to add those together for that player and give a total ($accbonus) but instead it's adding the bonus up for each player and then giving the next player the combined bonus. So the last player to join, get a combined $accbonus for all other players. How do I add all the addons bonus for each part, per player and not give the next player a bonus because of it? I'm using adodb and mySQL. while($getentries1 = $getentries->fetchrow()) { $getcar = $db->execute("SELECT c.car_name, co.efficiency, co.gas, c.max_speed, c.acceleration, c.max_corner_speed, co.driving_skills, co.car_id, co.id as carid, p.username, p.driving_hours, p.id FROM Cars c INNER JOIN cars_owned co ON co.car_id=c.car_id INNER JOIN players p ON p.id=co.player_id WHERE co.id=?", array($getentries1['car_owned_id'])); $getcar1 = $getcar->fetchrow(); $getaddons = $db->execute("SELECT u.acceleration_increase, u.corner_speed_increase, u.top_speed_increase FROM car_upgrades u LEFT JOIN cars_upgradesinstalled cui ON cui.addon_id=u.id WHERE cui.car_id=?", array($getcar1['carid'])); while ($getaddons1 = $getaddons->fetchrow()) { $supbonus += $getaddons1['corner_speed_increase']/100; $speedbonus += $getaddons1['top_speed_increase']/100; $accbonus += $getaddons1['acceleration_increase']/100; } //add bonus equipment $acceleration = $getcar1['acceleration']+($getcar1['acceleration']*$accbonus); $speed = $getcar1['max_speed']+($getcar1['max_speed']*$speedbonus); $suspension = $getcar1['max_corner_speed']+($getcar1['max_corner_speed']*$accbonus); Link to comment https://forums.phpfreaks.com/topic/184192-need-help-adding-variables-within-a-loop/ Share on other sites More sharing options...
cdoyle Posted December 6, 2009 Author Share Posted December 6, 2009 I've been trying different things, and so far I haven't had any luck. I'm pretty sure that this # while ($getaddons1 = $getaddons->fetchrow()) # { # $supbonus += $getaddons1['corner_speed_increase']/100; # $speedbonus += $getaddons1['top_speed_increase']/100; # $accbonus += $getaddons1['acceleration_increase']/100; # # } is either not in the right place, or isn't the right way to do what I need to do. Everything else works OK in my page, just adding up these addon's isn't working. I hope someone has an idea. Link to comment https://forums.phpfreaks.com/topic/184192-need-help-adding-variables-within-a-loop/#findComment-972544 Share on other sites More sharing options...
cdoyle Posted December 8, 2009 Author Share Posted December 8, 2009 Anyone have any ideas on what I could do, to get this to work right? Link to comment https://forums.phpfreaks.com/topic/184192-need-help-adding-variables-within-a-loop/#findComment-973189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.