sjones Posted October 24, 2008 Share Posted October 24, 2008 I have two tables one for products (product) and one for orders (orders) The product description is in the product table (product_short_desc). However the session_id is in the orders table (cart_session_id) this query below will return everything from the orders table (but no product description obviously) $query = "SELECT * FROM orders WHERE (cart_session_id = '".$sid."')"; ___________________________________________________ Then I tried this one and get "Zero" results $query = "SELECT orders.product_name, orders.cart_quantity, product.product_short_desc FROM orders, product WHERE orders.cart_session_id = '".$sid."' AND orders.product_name = product.product_name"; I'm just in building phase now so any suggestions on how I can achieve this will be helpfull - Thanks Link to comment https://forums.phpfreaks.com/topic/129875-query-help-needed/ Share on other sites More sharing options...
Chicken Little Posted October 24, 2008 Share Posted October 24, 2008 Have you forced referential integrity between the two tables? Link to comment https://forums.phpfreaks.com/topic/129875-query-help-needed/#findComment-673322 Share on other sites More sharing options...
fenway Posted October 24, 2008 Share Posted October 24, 2008 Switch this to a LEFT JION. Link to comment https://forums.phpfreaks.com/topic/129875-query-help-needed/#findComment-673364 Share on other sites More sharing options...
mrmitch Posted October 24, 2008 Share Posted October 24, 2008 What happens when you run the query directly against the db? Switching to a left join will only pull out the left table, orders. It's not finding a match, so it's not displaying anything. If there is supposed to be a match, then you have a bigger problem. I'd also suggest using id's and not names on matching. Databases match integers much faster than strings. Link to comment https://forums.phpfreaks.com/topic/129875-query-help-needed/#findComment-673824 Share on other sites More sharing options...
fenway Posted October 27, 2008 Share Posted October 27, 2008 Switching to a left join will only pull out the left table, orders. It's not finding a match, so it's not displaying anything. If there is supposed to be a match, then you have a bigger problem. Unless that's part of the design. Link to comment https://forums.phpfreaks.com/topic/129875-query-help-needed/#findComment-675940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.