Jump to content

Query help needed


sjones

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.