Tyr Posted February 10, 2010 Share Posted February 10, 2010 How would one go about updating multiple differant people in a selected range. for example $db->query("UPDATE gangs SET gangMONEY=gangMONEY+$vault WHERE gangID={$test['gangID']}"); is my query. I am wanting it to update more than 1 gang. Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 10, 2010 Share Posted February 10, 2010 depending on what exactly your asking for there are ways to simply update them like the following [mysql] UPDATE `users` SET `cash` = `cash` + 100 WHERE `donatordays` >= 5 [/mysql] basically it adds 100 cash to anyone who's got 5 or more donatordays Quote Link to comment Share on other sites More sharing options...
Tyr Posted February 10, 2010 Author Share Posted February 10, 2010 Well it's a bit more fickle than that sadly. Basically I am calling to another table with a JOIN statement and providing the JOINED TABLE matches info in the Gang table it should only update gangs that match the selected join base num_rows so say 3 out of 5 gangs match up with the Joined table, i want the 3 gangs to be updated on a query. Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 10, 2010 Share Posted February 10, 2010 ah then a while function maybe in order? Quote Link to comment Share on other sites More sharing options...
Tyr Posted February 10, 2010 Author Share Posted February 10, 2010 Right I attempted the while function and damn page timed out so not sure if i added it properly Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 10, 2010 Share Posted February 10, 2010 paste your code ill see if i can help Quote Link to comment Share on other sites More sharing options...
Tyr Posted February 10, 2010 Author Share Posted February 10, 2010 Some of the random echo'd text is just me testing queries <?php include "globals.php"; $_GET['ID']= abs((int) $_GET['ID']); $_POST['qty']= abs((int) $_POST['qty']); $query1 = $db->query("SELECT g.`gangID`,t.`gangID`,t.`city`,t.`tax` FROM `gangs` g LEFT JOIN `land` t ON g.`gangID`=t.`gangID` WHERE g.`gangID`={$ir['gang']} AND t.`city`={$ir['location']}"); $test= $db->fetch_row($query1); $taxquery = $db->query("SELECT `tax` FROM `land` WHERE `city`={$ir['location']}"); $taxation = $db->fetch_row($taxquery); if(!$_GET['ID'] || !$_POST['qty']) { print "Invalid use of file"; } else if($_POST['qty'] <= 0) { print "You have been added to the delete list for trying to cheat the game."; } else { $q=$db->query("SELECT * FROM items WHERE itmid={$_GET['ID']}"); if(mysql_num_rows($q) == 0) { print "Invalid item ID"; } else { $itemd=$db->fetch_row($q); if($ir['money'] < $itemd['itmbuyprice']*$_POST['qty']) { print "You don't have enough money to buy this item!"; $h->endpage(); exit; } if($itemd['itmbuyable'] == 0) { print "This item can't be bought!"; $h->endpage(); exit; } $price=($itemd['itmbuyprice']*$_POST['qty']); $tax = $price*$taxation['tax']; $taxprice = $price+$tax; $counting = $db->query("SELECT gangID FROM land WHERE city={$ir['location']} ORDER BY gangID ASC"); $count = $db->fetch_row($counting); $test = $db->num_rows($counting); $vault = $tax/$test; echo "".$vault.""; if($ir['money'] < $taxprice) { echo "You can not afford the Tax on this item"; $h->endpage(); exit; } item_add($userid, $_GET['ID'], $_POST['qty']); while($rr = $db->fetch_row($counting)) { if(!$db->num_rows($query1)) { echo "".$rr['gangID'].""; echo "Since Your gang does not own land in this location, you are charged a tax fee of ".$taxation['tax']." percent which goes towards gangs who do own land. Your grand total comes out to ".$taxprice." dollars."; $db->query("UPDATE users SET money=money-$taxprice WHERE userid=$userid"); $db->query("UPDATE gangs SET gangMONEY=gangMONEY+$vault WHERE gangID={$rr['gangID']}"); $db->query("INSERT INTO itembuylogs VALUES ('', $userid, {$_GET['ID']}, $taxprice, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$taxprice}')"); } } } $db->query("UPDATE users SET money=money-$price WHERE userid=$userid"); $db->query("INSERT INTO itembuylogs VALUES ('', $userid, {$_GET['ID']}, $price, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$price}')"); echo "You bought ".number_format($_POST['qty'])." ".stripslashes(htmlentities($itemd['itmname']))."(s) for \$".number_format($price).""; } $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 10, 2010 Share Posted February 10, 2010 Weird it looks fine to me, you just get a timed out error? Quote Link to comment Share on other sites More sharing options...
Tyr Posted February 10, 2010 Author Share Posted February 10, 2010 Nay,I was, I managed to fix that had a } in the wrong place Now it's just updating 1 gang tho >< the last gang. I set the gangs as a test 2 own land in that city the user i'm buying the item with has no land nor is he in a gang it takes his money, that tax bit works fine deducting but where it updates all the gangs a set amount of tax money only the last gang is getting the income Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 10, 2010 Share Posted February 10, 2010 That is very unusual, Maybe just run back over the code, when i get something wrong or a error i normally run over my code or recode specific parts to be sure they are correct. Quote Link to comment Share on other sites More sharing options...
Tyr Posted February 10, 2010 Author Share Posted February 10, 2010 yes,I think i'm going to recode entire thing from scratch and see what i get blah Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.