shaved92bravada Posted December 29, 2008 Share Posted December 29, 2008 I need to know what I am doing wrong here.... $items=('61,62,63,64'); $checkitems = sprintf ( "SELECT COUNT(`inv_id`) FROM inventory WHERE ((`inv_itemid` IN ('%s') AND (`inv_userid` = '%u'))", $items, abs(@intval($userid)) ); $items = $db->query($checkitems); QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Query was SELECT COUNT(`inv_id`) FROM inventory WHERE ((`inv_itemid` IN ('61,62,63,64') AND (`inv_userid` = '1')) Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted December 29, 2008 Share Posted December 29, 2008 Re: Another problem need help with Try $items=('61,62,63,64'); $checkitems = sprintf ( "SELECT COUNT(`inv_id`) FROM inventory WHERE `inv_itemid` IN ('%s') AND `inv_userid` = '%u'", $items, abs(@intval($userid)) ); $items = $db->query($checkitems); & post back. Quote Link to comment Share on other sites More sharing options...
POG1 Posted December 29, 2008 Share Posted December 29, 2008 Re: Another problem need help with echo the sprintf to see if it is an error in there, if not you will know its the query. Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted December 29, 2008 Share Posted December 29, 2008 Re: Another problem need help with http://www.deadlykillah.com/test.php Produce's: SELECT COUNT(`inv_id`) FROM inventory WHERE ((`inv_itemid` IN ('1,5,9,10') AND (`inv_userid` = '1')) Try my code and see if anything happen's. Quote Link to comment Share on other sites More sharing options...
POG1 Posted December 29, 2008 Share Posted December 29, 2008 Re: Another problem need help with I think it will be something to do with IN('%s') Or would count() be needed? that may be the cause of the error Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted December 29, 2008 Share Posted December 29, 2008 Re: Another problem need help with Use my one. I am sure it will work. Quote Link to comment Share on other sites More sharing options...
Floydian Posted December 29, 2008 Share Posted December 29, 2008 Re: Another problem need help with Try $items=('61,62,63,64'); $checkitems = sprintf ( "SELECT COUNT(`inv_id`) FROM inventory WHERE `inv_itemid` IN ('%s') AND `inv_userid` = '%u'", $items, abs(@intval($userid)) ); $items = $db->query($checkitems); & post back. Killah is on the right track here. You had a missmatched set of parens. The only other thing I see that's a problem is your in() function takes a CSV, but you've enclosed your entire CSV in quotes. in(%s) is the way you wanna do that, and not in('%s') The key there, is using %s does not always require quotes. You're outputting a CSV composed entirely of numbers. If you had strings, you still wouldn't use quotes around the %s because you would need quotes around each entry: in('a', 'b', 'c') Does that make sense? Quote Link to comment Share on other sites More sharing options...
shaved92bravada Posted December 29, 2008 Author Share Posted December 29, 2008 Re: Another problem need help with yeah it makes perfect sense and tyvm for explaining it. The task at hand is to make it where if the player doesn't have items ( id x, id x, id x, id x ) in their inventory then they cannot move forward until they have the required items in their inventory...... so wouldn't if(!$db->num_rows($items)) { echo ' you have to have blah blah to blah blah '; } is that correct or how to I tell it that if they don't have those they cannot move on?? Quote Link to comment Share on other sites More sharing options...
Floydian Posted December 29, 2008 Share Posted December 29, 2008 Re: Another problem need help with Using the code you have, and assuming your query is working properly, you'd take the var $items, and put it in an if. if ($items < the number of items required) { // you don't have the required items... } else { // you do have the required items... } Quote Link to comment Share on other sites More sharing options...
shaved92bravada Posted December 29, 2008 Author Share Posted December 29, 2008 Re: Another problem need help with ok well apparently my query isn't working correctly because I don't have the required items in my inventory and it is letting me go onto the next step...... so any help on what I am doing wrong would be greatly appreciated..... I have been working on this mod for about a month now and decided to go ahead and get this step out of the way before I tried to progress any further...... below is the following query which doesn't give any errors, it just doesn't work correctly I guess.... $checkitems = sprintf ( "SELECT COUNT(`inv_id`) FROM inventory WHERE `inv_itemid` IN (%s) AND `inv_userid` = '%u'", $items, abs(@intval($userid)) ); $items = $db->query($checkitems); Quote Link to comment Share on other sites More sharing options...
POG1 Posted December 30, 2008 Share Posted December 30, 2008 Re: Another problem need help with try the query in phpmyadmin Quote Link to comment Share on other sites More sharing options...
shaved92bravada Posted December 30, 2008 Author Share Posted December 30, 2008 Re: Another problem need help with still no luck as of yet.... I am gonna keep workin on it and see if I can figure out what the problem is.... I know I can get it to work by running a seperate query for each item but then that wouldn't be efficient would it lol... Thanks for all the help so far and all the help to hopefully swing my way.... Quote Link to comment Share on other sites More sharing options...
Decepti0n Posted December 30, 2008 Share Posted December 30, 2008 Re: Another problem need help with $items = '61,62,63,64'; $itemsq = $db->query("SELECT COUNT(`inv_id`) as `c` FROM inventory WHERE `inv_itemid` IN (" . $items . ") AND `inv_userid` = '" . $userid . "'"); $fetch = mysql_fetch_assoc($itemsq); if ($fetch['c'] >= 1) { // Continue } else { // no } Although that i think would only work if they had one of the four items, if you needed all four, then try this: if ($fetch['c'] == 4) { // Continue } else { // no } Quote Link to comment Share on other sites More sharing options...
shaved92bravada Posted December 30, 2008 Author Share Posted December 30, 2008 Re: Another problem need help with that worked like a charm.... thank you so very very very much.... +1 for you... Quote Link to comment Share on other sites More sharing options...
Floydian Posted December 30, 2008 Share Posted December 30, 2008 Re: Another problem need help with Now you gotta make sure your inventory is quantized.... Quote Link to comment Share on other sites More sharing options...
CtrlFreq Posted January 29, 2009 Share Posted January 29, 2009 Re: Another problem need help with I need to know what I am doing wrong here.... Your problem is because your list of items is being passed to sql as a single string. Make items an array and then implode it with a comma to make the list for your IN clause. $items = array(61,62,63,64); $checkitems = sprintf ( "SELECT COUNT(`inv_id`) FROM inventory WHERE ((`inv_itemid` IN (%s) AND (`inv_userid` = '%u'))", implode(",", $items), abs(@intval($userid)) ); $items = $db->query($checkitems); Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted January 30, 2009 Share Posted January 30, 2009 Re: Another problem need help with OR simple as this: $items = '61,62,63,64'; $items = mysql_query('SELECT COUNT(`inv_id`) FROM `inventory` WHERE `inv_itemid` IN('.$items.') AND `inv_userid` = ".$ir['userid']); Quote Link to comment Share on other sites More sharing options...
CtrlFreq Posted January 30, 2009 Share Posted January 30, 2009 Re: Another problem need help with OR simple as this: They were both two lines of code, the sprintf was just expanded for readability :-P Quote Link to comment Share on other sites More sharing options...
POG1 Posted January 30, 2009 Share Posted January 30, 2009 Re: Another problem need help with OR simple as this: $items = '61,62,63,64'; $items = mysql_query('SELECT COUNT(`inv_id`) FROM `inventory` WHERE `inv_itemid` IN('.$items.') AND `inv_userid` = ".$ir['userid']); I don't think that wont work.. If you look at the in function is needs a list of values separated with commas. Your example will look like this.. IN('61,62,63,64') Wouldn't the apostrophes treat it as a string and not an array? Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted January 30, 2009 Share Posted January 30, 2009 Re: Another problem need help with Um pog1. You do know that when calling a string the ' ' are removed right? And i have seen people say it's better for IN('8,8,8') better than IN(8,8,8); even decepti0n done it on the event mod. 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.