War_Hero Posted November 5, 2008 Posted November 5, 2008 Hi all. I'm having a bit of trouble with an inventory/item query. I'm trying to select an item and it's quantity from the inventory, then compare it against a pre-defined variable. If the quantity is smaller than the predefined variable, a die() statement is outputted. However, even if I have enough of the item, it still outputs the die() statement. I'll post the bit of code that I'm working with. $id = $db->query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid = 107 WHERE iv.inv_userid = $userid LIMIT 1"); $r = $db->fetch_row($id); And the IF and DIE statements: elseif($r['inv_qty'] < $db_config['gym1bricks']) { die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some."); } $db_config['gym1bricks'] is set to 3840. Yet, even if I have 40000, I still get the DIE() statement. This is really getting to me now, as this is simple...ish, but I can't wrap my head around it. Can anyone help me? Any help will be highly appreciated. :) Quote
AlabamaHit Posted November 5, 2008 Posted November 5, 2008 Re: Inventory help try it without the LIMIT 1 in the query. Quote
War_Hero Posted November 5, 2008 Author Posted November 5, 2008 Re: Inventory help Thank you for your suggestion. Unfortunately, it still doesn't work. :( I've tried numerous things, but they haven't worked...... Quote
AlabamaHit Posted November 5, 2008 Posted November 5, 2008 Re: Inventory help is there something else above it to need the else if You should just need the if take the else out see if that its. if that dont try this... $run = sprintf("SELECT iv*, it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid = it.itmid WHERE iv.ivn_userid = %u AND it.itmid = %u", @intval($userid), @intval(107)); $runthis = $db->fetch_row($run); if($runthis['inv_qty'] < $db_config['gym1bricks']) { die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some."); } Also I dont know what the $db_config['gym1bricks'] is.... Quote
War_Hero Posted November 5, 2008 Author Posted November 5, 2008 Re: Inventory help It's in a nested IF statement: elseif($ir['gymsize'] == 32) { if($db->num_rows($query) <= 0) { die("You don't have any bricks to build your gym. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some."); } elseif($r['inv_qty'] < $db_config['gym1bricks']) { die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some."); } elseif($db->num_rows($query2) <= 0) { die("You don't have any cement to build your gym. Go <a href = 'buildgym.php?action=buycement' />here</a> to buy some."); } elseif($m['inv_qty'] < $db_config['gym1cement']) { die("You have cement, but you don't have enough. Go <a href = 'buildgym.php?action=buycement' />here</a> to buy some."); } elseif(($db->num_rows($query) <= 0) AND ($db->num_rows($query2) <= 0)) { die("You don't have any bricks or cement to build your gym. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy bricks, and <a href = 'buildgym.php?action=buycement' />here</a> to buy cement."); } else { $build1 = sprintf("UPDATE `users` SET `buildtime` = '%d', `gymbuilt` = '%d' WHERE `userid` = ('%u')", $db_config['buildtime1'], 1, $userid); $db->query($build1); item_remove($userid, 107, $db_config['gym1bricks']); item_remove($userid, 108, $db_config['gym1cement']); print "You have now started work on your gym. It will be completed in {$db_config['buildtime1']} minutes. <font color = 'red' /><b />NOTE: You can <u />NOT</u> change anything now, or cancel the construction of your gym.[/b]</font> You will be able to access all other areas of Global Conflict 2250 during the construction of your gym. <a href = 'index.php' />Click Here</a> to go home."; } } But I can't see anything wrong with that...so it may be my SELECT query. Quote
AlabamaHit Posted November 5, 2008 Posted November 5, 2008 Re: Inventory help i changed my other post check it out...... Quote
War_Hero Posted November 5, 2008 Author Posted November 5, 2008 Re: Inventory help Thank you. Unfortunately, it still doesn't work. I get this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/home/*********/domains/*******/public_html/class/class_db_mysql.php on line 71 You have bricks, but you don't have enough. Go here to buy some. I'm still getting the DIE() statement. :( Why is this so hard!? :-P Quote
AlabamaHit Posted November 5, 2008 Posted November 5, 2008 Re: Inventory help $run = sprintf("SELECT iv*, it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid = it.itmid WHERE iv.ivn_userid = %u AND it.itmid = %u", @intval($userid), @intval(107)); $humm = $db->query($run); $runthis = $db->fetch_row($humm); if($runthis['inv_qty'] < $db_config['gym1bricks']) { die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some."); } Maybe its me but i think i missed someething im still new to sprintf so try that one maybe i missed that....I'm sjure its just something small...like a typo or query typed wrong.. Quote
War_Hero Posted November 5, 2008 Author Posted November 5, 2008 Re: Inventory help Thank you so very much!!! It works a treat. I just had to change a ivn to an inv and one other thing. :) Thank you very much for helping me out. I will remember and practice this for when I need it again. Quote
AlabamaHit Posted November 5, 2008 Posted November 5, 2008 Re: Inventory help lol i see that now i typed it wrong, lol...i put iv.ivn_userid, lol.... Sorry about that, and good catch.. Glad to help also.. Quote
War_Hero Posted November 5, 2008 Author Posted November 5, 2008 Re: Inventory help Lol. Thanks again. :) Now I can finally finish off this mod. :-D lol 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.