djfox Posted January 2, 2008 Share Posted January 2, 2008 I have the following code: <?php if ($lev > 0){ echo "<p>"; $res = mysql_query("SELECT id, name, excit, excam, exc FROM clothing WHERE id=$it"); $item = mysql_fetch_row($res); mysql_free_result($res); $res2 = mysql_query("SELECT id, name FROM collection WHERE id=$item[2]"); $item2 = mysql_fetch_row($res2); mysql_free_result($res2); $res3 = mysql_query("SELECT COUNT(*) FROM coll_inven WHERE item=$item[2] AND user='$loggeduser'"); $count = mysql_fetch_row($res3); mysql_free_result($res3); if ($item[4] == 1) { if ($count[0] >= $item[3]) { } elseif ($count[0] < $item[3]){ $more = $item[3] - $count[0]; echo "<p>You don`t have enough <b>$item2[1]</b>. You need <b>$more</b> more to make the exchange."; } } elseif ($item[4] ==0){ echo "This is not an exchange item!"; } } ?> What this page should do is check to see if someone has enough of a certain item in their inventory to make an exchange. If they don`t have enough, the exchange is not made, but if they do have enough, the exchange needs to take place. The code would need to delete the number of items needed ($item[3]) from coll_inven. Example: Item the person wants to exchange for is Disco Ball ($item[1]) They need 5 ($item[3]) glass shards ($item[2]/$item2[1]) The person has 5 ($count[0]) in their inventory So 5 ($item[3]) glass shards ($item[2]) from coll_inven that belong to the logged in person ($loggeduser) need to be deleted from the database. How will I tell the code to delete only 5 ($item[3]) entries in coll_inven where item=$item[2] and user=$loggeduser ? Will I be using LIMIT=$item[3] ? Quote Link to comment Share on other sites More sharing options...
djfox Posted January 3, 2008 Author Share Posted January 3, 2008 I tried this: mysql_query("DELETE FROM coll_inven2 WHERE item=$item[2] AND user='$loggeduser' LIMIT $item[3] ;"); or die(mysql_error()); But I get this error: Parse error: syntax error, unexpected T_LOGICAL_OR in /home/secrett1/public_html/exchange3.php on line 83 (Line 83 is the line above.) I`m using coll_inven2 (with some play entries) to run tests for the code so that I don`t cause anything disastrous to happen to the real info. Quote Link to comment Share on other sites More sharing options...
awpti Posted January 3, 2008 Share Posted January 3, 2008 mysql_query("DELETE FROM coll_inven2 WHERE item=$item[2] AND user='$loggeduser' LIMIT $item[3]") or die(mysql_error()); Fix'd. You had a ; in a bad place. Also, don't put ;'s inside mysql_query() - unnecessary 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.