kybaker Posted April 29, 2010 Share Posted April 29, 2010 Hey all, To get to the point....I need to be able to update multiple users based on whether they selected the correct answer or not. As of right now my code runs through and selects the first user and if they are correct it updates their income to the correct amount. This does not happen for multiple users... its stopping my iteration after the first person. Anyone know what I'm doing wrong? if($result) { //pull information from bet where bet is on right game $income_qry = "SELECT * from makeBets where sport_event='$game_id'"; $income_results = mysql_query($income_qry) or die("Query failed"); while($incomeupdate = mysql_fetch_array($income_results)){ $bet_amt = $incomeupdate['bet_amt']; $selection = $incomeupdate['selection']; $member = $incomeupdate['member_id']; //Query to get original income $iqry = "SELECT income FROM users WHERE member_id ='$member'"; $income_results = mysql_query($iqry); $income_array = mysql_fetch_array($income_results); $income = $income_array['income']; //if selection is a winner; update income if($selection==$winner){ //add original income + (bet_amt *2) $new_income = $income + $bet_amt + $bet_amt; $qry_update_income = "UPDATE users SET income='$new_income' WHERE member_id ='$member'"; $update_results = mysql_query($qry_update_income) or die("Update Income Query Failed"); } else { continue; } } header("location: update-games-success.php"); exit(); } else{ echo "Update Game Winner Query Failed"; } Link to comment https://forums.phpfreaks.com/topic/200168-helping-update-multiple-users/ Share on other sites More sharing options...
Ken2k7 Posted April 29, 2010 Share Posted April 29, 2010 Hello, The problem is that you ran this line inside your while loop. $income_results = mysql_query($iqry); Because you overwrote the variable $income_results, the while loop no longer has the result set you wished to loop through. Best, Ken Link to comment https://forums.phpfreaks.com/topic/200168-helping-update-multiple-users/#findComment-1050555 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.