Depthcharge Posted March 11, 2008 Share Posted March 11, 2008 Hey all, I'm new to php and the boards here but I need some help badly. I'm trying to run a series of four queries to populate corresponding tables on my page. The oddness is that I can only run one of these queries and it doesn't matter which one it is, as long as its the first on the page. To verify this I logged into mysql directly and tested the queries and all of them run as desired. The code for all 4 tables is identical save for the query table names. Basically what happens is the first query runs and the first table gets populated. Following that, the second query fails and this message is displayed: "Couldn�t execute query: 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 ') AS EnginesEquipped ON Engine.EngineID = EnginesEquipped.EngineID' at line 1" Clearly the syntax is alright though since I the problem is completely order independent and the mysql client has no problems with it, right? The relevant PHP code is below: <code> // TABLE OPENING TAGS AND TABLE HEADERS... <?php $sql = "SELECT * FROM Armor LEFT JOIN (SELECT * FROM DesignHasArmor WHERE DesignHasArmor.DesignID = $DesignID) AS ArmorsEquipped ON Armor.ArmorID = ArmorsEquipped.ArmorID"; $result = mysql_query($sql) or die("Couldn’t execute query: ". mysql_error()); $rows = mysql_num_rows($result); if ($rows != 0) { while ($row = mysql_fetch_array($result)) { extract($row); // OUTPUT STUFF HERE... } } ?> // TABLE CLOSING TAGS... </code> Ok, I hope that explains my hang up. If anyone has any ideas I'd love to hear them. -DC Quote Link to comment https://forums.phpfreaks.com/topic/95567-strange-mysql-query-troubles/ Share on other sites More sharing options...
sasa Posted March 11, 2008 Share Posted March 11, 2008 try $sql = "SELECT * FROM Armor LEFT JOIN DesignHasArmor ON DesignHasArmor.DesignID = $DesignID AND Armor.ArmorID = ArmorsEquipped.ArmorID"; Quote Link to comment https://forums.phpfreaks.com/topic/95567-strange-mysql-query-troubles/#findComment-489430 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.