Tyr Posted February 10, 2010 Posted February 10, 2010 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. Quote
Zero-Affect Posted February 10, 2010 Posted February 10, 2010 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 Quote
Dabomstew Posted February 11, 2010 Posted February 11, 2010 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); Quote
Zero-Affect Posted February 11, 2010 Posted February 11, 2010 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 ); 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.