Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with a query


bobg7

Recommended Posts

I could use some help with a query, what I'm trying to do is pull customers_name and customers_state from orders and title from orders_total. Here's the query I'm entering:

 

SELECT customers_name, customers_state, title
FROM orders, orders_total

 

Problem is it gives me 1 entry for each item it finds but it only displays this:

customers_name customers_state title

Test Account Florida Sub_Total

 

If I change the query to:

 

SELECT title, customers_name, customers_state
FROM orders_total, orders

 

I get this:

title customers_name customers_state

Sub_Total Test Account Florida

Federal Express... Test Account Florida

FL TAX 7.0% Test Account Florida

Total Test Account Florida

(repeating 100+times)

 

Something like 100+ entries per item. All I would like for it to do is look like this example but only 1 entry per item.

 

Hope this makes sense and thanks in advance,

 

Bob

Installed Contributions: CCGV, Close Popup, Dynamic Meta Tags, Easy Populate, Froogle Data Feeder, Google Position, Infobox Header Entire Row, Live Support for OSC, PayPal Seal with CC images, Report_m Sales, Shop by Price Revised, SQL Updater, Who's Online Enhancement, Footer, GNA EP Assistant and still going.

Link to comment
Share on other sites

select o.customers_name, o.customers_state, ot.title from orders o, orders ot where o.orders_id = ot.orders_id and o.customers_id = '" . $some_variable_that_tells_it_what_customer_id_to_use . "'"

 

Adding the alias "o" and "ot" tells sql which table to use for each of the fields. The where clause tells sql to get all orders for customer_id, and then match the information from both tables.

 

Hope that makes sense. Otherwise the query you have has no way of telling what information to select. That is why you are seeing the results you are.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...