Jump to content
MakeWebGames

Hm, Another question, quick fix


Tyr

Recommended Posts

Thinking maybe my eyes are getting lazy

 

$bombexists = "SELECT in.inv_itemid,in.inv_userid,i.itmid,i.itmname,u.userid FROM inventory in LEFT JOIN items i ON in.inv_itemid=i.itmid LEFT JOIN users u ON in.inv_userid=u.userid WHERE in.inv_itemid=3";
$bombboom = $db->query($bombexists);

 

Can anyone see the err here?

I'm getting

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 'in LEFT JOIN items i ON in.inv_itemid=i.itmid LEFT JOIN users u ON in.inv_userid' at line 1

But i just for the life of me cant see the error.

Link to comment
Share on other sites

weird this reminds me of immortal thug he can't do left join so good either but..

  $bombexists = "SELECT in.`inv_itemid`, `inv_userid`, i.`itmid`, `itmname`, u.`userid` FROM `inventory` in LEFT JOIN `items` i ON in.`inv_itemid` = i.`itmid` LEFT JOIN `users` u ON in.`inv_userid` = u.`userid` WHERE in.`inv_itemid` = 3";
  $bombboom = $db->query( $bombexists );

should work

Link to comment
Share on other sites

This happens because "in" has special meaning in MySQL, so using it as a table alias like that will cause errors.

To stop this error occurring, enclose "in" in `` quotes.

As such:

$bombexists = "SELECT `in`.inv_itemid,`in`.inv_userid,i.itmid,i.itmname,u.userid FROM inventory `in` LEFT JOIN items i ON `in`.inv_itemid=i.itmid LEFT JOIN users u ON `in`.inv_userid=u.userid WHERE `in`.inv_itemid=3";
$bombboom = $db->query($bombexists);
Link to comment
Share on other sites

ah you have a point there because IN is a function in MySQL it will error, You could just rename in to inv =>

$bombexists = "SELECT inv.`inv_itemid`, `inv_userid`, i.`itmid`, `itmname`, u.`userid` FROM `inventory` inv LEFT JOIN `items` i ON inv.`inv_itemid` = i.`itmid` LEFT JOIN `users` u ON inv.`inv_userid` = u.`userid` WHERE inv.`inv_itemid` = 3";
  $bombboom = $db->query( $bombexists );
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...