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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.