Jump to content
MakeWebGames

Another problem need help with


shaved92bravada

Recommended Posts

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'))

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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...

}

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

  • 5 weeks later...

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);
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...