This topic is locked

Trouble with custom query and master detail link

7/11/2006 9:40:15 PM
PHPRunner General questions
D
Dale author

Ive been working on this one most of the day.
I finally got the Edit SQL query to work, but now I have an issue when selecting a list item for editing.
I have two tables, customers and purchases.

They both have a field called customer_id
I finally got the query below to work that would join the tables and retrieve all the fields needed.
select

`customer`.customer_id,

`customer`.name,

`customer`.contact_1,

`customer`.contact_2,

`customer`.email_1,

`customer`.created_date,

`customer`.address1,

`customer`.memo,

`customer`.address2,

`customer`.city_id,

`customer`.postal_zip_code,

`customer`.email_2,

`customer`.phone,

`customer`.fax,

`customer`.cell,

`customer`.other,

`customer`.status_id,

`customer`.tax1_exempt,

`customer`.tax2_exempt,

`customer`.tax3_exempt,

`customer`.discount_rate,

`customer`.discount_amount,

`customer`.www_url,

`customer`.industry_id,

`purchases`.desdate0,

`purchases`.date_0,

`purchases`.ddate_0

From `customer`

INNER JOIN purchases ON (`customer`.customer_id = `purchases`.customer_id)

WHERE (purchases.ddate_0 != 1)
I would like to add the sort order but I get an sql error when I add the piece below.
ORDER BY `purchases`.date_0 ASC
Without the ORDER BY, I do get a list correctly.

But when I select edit I get an error
Error description: Column: 'customer_id' in field list is ambiguous

Error file : localhost/yellowsheet/purchases_list.php?masterkey=4174
The purchases table, I have defined a master link to the customers in PHP runner.
I hope this is enough to show. I must be doing something wrong with my syntax or something, I hope.

Any suggestions.
Thankyou in advance.

Alexey admin 7/12/2006

Dale,
don't add ORDER BY clause to SQL query manually.

Use Order By box for this.
When you use joined or calculated fields you need to modify GetFullFieldName function as described in PHPRunner help:

http://www.xlinesoft.com/phprunner/docs/us...sql_queries.htm

D
Dale author 7/12/2006

Thanks for the suggestion. I will work on that today.
When I use the order by field and I select CHANGE, I do not get the fields from the joined table listed.

But I will add the order by clause without using the picklist.
I will check into the GetFullName area you mentioned.
Thanks for the response.