boots Posted February 22, 2012 Posted February 22, 2012 Im trying to change this so they dont add to the inventory as single items if($r['rewardtype'] == 3) { $juk=mysql_query("SELECT * FROM items WHERE itmid=$reward",$c); $item=mysql_fetch_array($juk); mysql_query("INSERT INTO votes values ($userid,$id)",$c); mysql_query("INSERT INTO inventory values ('',$reward,$userid,1)",$c); <<<<<<<<<< this line event_add($userid,"Thank you for voting! You have receieved a/an {$item['itmname']}!", $c); } if($r['rewardtype'] == 4) this is what i have so far but still cant get it to work if($r['rewardtype'] == 3) { $juk=mysql_query("SELECT * FROM items WHERE itmid=$reward",$c); $item=mysql_fetch_array($juk); mysql_query("INSERT INTO votes values ($userid,$id)",$c); item_add($userid,$reward,1)",$c); event_add($userid,"Thank you for voting! You have receieved a/an {$item['itmname']}!", $c); } if($r['rewardtype'] == 4) Quote
newttster Posted February 22, 2012 Posted February 22, 2012 Do you mean that you want to add more than one item at a time or multiples of one item? Quote
boots Posted February 22, 2012 Author Posted February 22, 2012 The script is for my voting page i have items as rewards for voters , the problem is when items are given they go in the inventory as single items. i want them to group together instead of loads of single items if they get a will potion then it adds to the rest of the will potions not a long list of potions Quote
peterisgb Posted February 23, 2012 Posted February 23, 2012 $used=array(); $q=mysql_query("SELECT * FROM inventory WHERE inv_userid=$userid"); while ( $r=mysql_fetch_array($q) ) { if ( ! in_array ( $r['inv_id'], $used ) ) { $currdel=array(); $used[] =$r['inv_id']; $currdel[]=$r['inv_id']; $amount=$r['inv_qty']; $q2=mysql_query("SELECT * FROM inventory WHERE inv_userid=$userid AND inv_itemid = {$r['inv_itemid']} AND inv_id != {$r['inv_id']}"); while ( $r2 = mysql_fetch_array($q2) ) { $used[]=$r2['inv_id']; $currdel[]=$r2['inv_id']; $amount+=$r2['inv_qty']; } mysql_query("DELETE FROM inventory WHERE inv_id IN(".implode(",",$currdel).")"); mysql_query("INSERT INTO inventory VALUES('', {$r['inv_itemid']}, $userid, $amount)"); } } this might help aswell, Quote
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.