I need a join query for fetching data when I click a button. Click section is done with the help of PHP and jQuery. But join query is failed. Please help me to solve this issue.
I tried query is
SELECT events.id,
form_values.id,
form_values.value,
form_fields.title,
form_fields.relation FROM events
INNER JOIN form_values
ON form_values.parent_id = events.customer_id
INNER JOIN form_fields
ON form_fields.id = form_values.form_field_id
WHERE form_fields.relation = 'event' AND events.id = '10029'
form_fields : Contains html input type details. For listing input types dynamically in to forms.
form_values : It is used to store dynamic values from input type.
form_values
form_field_id : related to form_fields.id
table
parent_id : related to events.customer_id
table
id form_field_id value parent_id
1 2 3 3119
2 5 yes 3119
3 10 yes 3119
4 10 yes 3118
5 6 text 3118
6 4 on 3118
form_fields
id title type option relation
2 select box select 2:CustomerTwo|3:CustomerThree customer
4 check box checkbox customer
5 radio one radio yes:Yes|no:No customer
6 text box textbox event
10 radio two radio yes:Yes|no:No event
events
id customer_id title price
10028 3119 Test1 125
10029 3118 Test2 132
10030 3118 Test3 133
Result I need is:
When I click a button id (events.id = 10029)
will pass and fetch data. I need result where form_fields.relation = "event"
and events.id = clicked ID(10029, 10028)
events.id form_fields.value form_fields.title form_fields.relation
10029 text text box event
10029 yes radio two event
10028 yes radio two event
I thing you have mistake in data entry, I run same query but I got the answer exactly you want, so check your data please, and the query I ran is SELECT events.id, form_values.id, form_values.value, form_fields.title, form_fields.relation FROM events INNER JOIN form_values ON form_values.parent_id = events.customer_id INNER JOIN form_fields ON form_fields.id = form_values.form_field_id WHERE form_fields.relation = 'event' AND events.id IN('10029','10028')