stockdalep Posted March 19, 2007 Share Posted March 19, 2007 Hi Could anyone help me with this I need to join one more table to this query named mens_dc I have tried various syntex but to no avail. $result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc"); Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/ Share on other sites More sharing options...
artacus Posted March 19, 2007 Share Posted March 19, 2007 Well first I have to know what mens_dc joins on. I assumed here that it was on the mdcID column. Change it to suit. SELECT * FROM cart JOIN items ON cart.itemID = items.itemID JOIN mens_dc ON items.mdcID = mens_dc.mdcID WHERE cart.cookieID = '$cartID' ORDER BY items.itemName " Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-210716 Share on other sites More sharing options...
stockdalep Posted March 19, 2007 Author Share Posted March 19, 2007 This is what we have now but it still does not work. $result = mysql_query("SELECT * FROM cart inner JOIN items ON cart.itemId = items.itemId inner JOIN mens_dc ON mens_dc.itemId = mens_dc.itemId WHERE cart.cookieId = GetCartId()"); Original code $result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc"); Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-210772 Share on other sites More sharing options...
stockdalep Posted March 20, 2007 Author Share Posted March 20, 2007 Hi I have 3 Tables as below I am trying to join both mens_dc and items tables to cart. If I use this sql ========================================================= $result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc"); ========================================================= We get the records from the items table but I cannot get both tables if I try ========================================================= select * from cart inner join items on cart.itemId = items.itemId inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc ===================================================== We then get nothing any ideas would be gratefully received Thanks. ====================================== Table Cart |cartId | cookieId | itemId | qty | Data 18 12344 2 1 19 12344 15 3 ====================================== Table items |itemId |itemName | itemDesc | itemPrice | Data 2 Trouser Trouser 5.50 ====================================== Table mens_dc |itemId |itemName | itemDesc | itemPrice | Data 15 Curtain Curtain 26.00 ====================================== Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-211146 Share on other sites More sharing options...
fenway Posted March 20, 2007 Share Posted March 20, 2007 What does the query string look like after the function call? That is, the statement that the server gets (hint: store it into a variable first). Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-211286 Share on other sites More sharing options...
stockdalep Posted March 20, 2007 Author Share Posted March 20, 2007 If I run it with just one join I get Resource id #4 With both we get nothing in the variable Resource id #3 Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-211304 Share on other sites More sharing options...
fenway Posted March 20, 2007 Share Posted March 20, 2007 I'm still looking for the answer to my question -- you're still running the queries, and I don't need that. Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-211388 Share on other sites More sharing options...
stockdalep Posted March 21, 2007 Author Share Posted March 21, 2007 Solved it with select from * cart inner join mensdc on cart.itemId = mensdc.itemId union all select from * cart inner join items on cart.itemId = items.itemId Quote Link to comment https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-212013 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.