x_mystico Posted December 11, 2010 Share Posted December 11, 2010 Firstly. My Code. $itemid = $_GET['id']; $sq = mysql_query("select * from `shop` where `id` = '$_GET[id]' ")or die (mysql_error()); $shop = mysql_fetch_array($sq);$invent= mysql_query("select * from items where `iid` = '$shop[id]'") or die(mysql_error()); $count = mysql_num_rows($invent); $upd = $invent1[amount]-1; if($count ==1){ mysql_query("delete from `items` where `iid`='$shop[id]' and `uid` = '$logged[id]' "); }elseif($count <=1){ $upd = $invent1[amount]-1; mysql_query("update `items` set `amount` ='$upd' where `uid` = '$logged[id]' and `iid` = '$shop[id]' ")or die(mysql_error()); } echo"item used:$shop[name]"; My Error is with the count What i want it to do, is if the var $invent1[amount] is more than 1, to take away 1 from it. e.g Amount(5)-1 =4 or if $invent1[amount] is only 0, to delete that row from the table. With my coding,No matter the value of $invent1[amount], It's always deleting that row from the table. Could anyone help me please? Quote Link to comment Share on other sites More sharing options...
Adam Posted December 13, 2010 Share Posted December 13, 2010 I'm not sure exactly how you want that fitting into your code, but to remove 1 from a variable if it's more than 1 is simple: if ($invent1['amount'] > 1) $invent1['amount']--; 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.