php - fetch data from multiple tables -
i have 4 table ads portal. firstly main table name ads
+-------------+ | field + +-------------+ | id + | ads_title + +-------------+
example data ads table;
+----+-----------------+ | id | ads_title | +----+-----------------+ | 20 | 2006 citroen c4 | | 27 | emekli ogretmen | | 28 | harika 10 n | | 34 | hatasiz boyasiz | | 49 | bayandan 2009 | +----+-----------------+
for ads specifications stored in table. table name ads_spc
+---------+ | field | +---------+ | id | | key_name| +---------+
data example ads_spc table;
+----+-------------+ | id | key_name | +----+-------------+ | 1 | date | | 2 | km | | 3 | colr | | 4 | engine | | 5 | pw. engine | | 6 | oil | | 7 | speed | | 8 | boody type | | 9 | traction | | 10 | warranty | +----+-------------+
lastly stored specification values ads_spc ads_id. table name ads_values
+------------+ | field | +------------+ | id | | ads_id | | spc_id | | value | +------------+
for example table data
+----+--------+--------+-------+ | id | ads_id | spc_id | value | +----+--------+--------+-------+ | 25 | 49 | 9 | 2119 | | 26 | 49 | 10 | 2131 | | 27 | 34 | 1 | 2010 | | 28 | 34 | 2 | 8900 | | 29 | 34 | 3 | 4 | | 30 | 34 | 4 | 22 | | 31 | 34 | 5 | 40 | | 32 | 34 | 6 | 60 | | 33 | 34 | 7 | 65 | | 34 | 34 | 8 | 66 | +----+--------+--------+-------+
i want using these tables list ads (table: ads) specifications (table:ads_spc) , ads values (table:ads_values) in data row.
union to; ads + ads_spc + ads_values (all values searchable)
i'm using case:
select sql_calc_found_rows * ads left join ads_spc aspc left join ads_values aval on aval.ads_id=a.id , aval.spc_id=aspc.spc_id
how can union 1 row? sorry english.
why union there no sense union should join these tables
select v.id, a.ads_title,s.key_name,v.value `ads` inner join `ads_values` v on (a.id =v.ads_id) inner join `ads_spc` s on(v.spc_id =s.id) s.key_name='color'
Comments
Post a Comment