Result of internal assembly

Looking at this array, you can see that only the value of foo6 is different from each parent key:

 Array ( [0] => Array ( [foo1] => Apple [foo2] => Banana [foo3] => Carrots [foo4] => Deer [foo5] => Feather [foo6] => Grapes ) [1] => Array ( [foo1] => Apple [foo2] => Banana [foo3] => Carrots [foo4] => Deer [foo5] => Feather [foo6] => Heater ) [2] => Array ( [foo1] => Apple [foo2] => Banana [foo3] => Carrots [foo4] => Deer [foo5] => Feather [foo6] => Quail Eggs ) ) 

Request:

 SELECT tpp.page_master_properties_style AS foo1, tpp.page_master_properties_bg AS foo2, tpp.page_master_properties_data AS foo3, tpp.page_properties_style AS foo4, tpp.page_properties_bg AS foo5, tpp.page_properties_data AS foo6, tobj.objects_script AS foo6 FROM templates t INNER JOIN category tc ON t.category_id = tc.category_id INNER JOIN page_properties tpp ON t.templates_id = tpp.templates_id INNER JOIN objects tobj ON t.templates_id = tobj.templates_id WHERE t.templates_id = ? 

where ? = 1 ? = 1

This is probably because there are several entries for the templates_id in the object table:

 +--------------+----------------+-----------------+ | objects_id | templates_id | objects_script | +--------------+----------------+-----------------+ | 1 | 1 | Grapes | | 2 | 1 | Heater | | 3 | 1 | Quail Eggs | | 4 | 2 | Milk | | 5 | 3 | Lemon | +--------------+----------------+-----------------+ 

I am wondering if there is a built-in function mySQL that can combine foo6 into a singular array, for example, to achieve this result:

 Array ( [foo1] => Apple [foo2] => Banana [foo3] => Carrots [foo4] => Deer [foo5] => Feather [foo6] => Array ( [0] => Grapes [1] => Heater [2] => Quail Eggs ) ) 
+4
source share
1 answer

This looks like work for group_concat in the mysql arsenal:

 SELECT tpp.page_master_properties_style AS foo1, tpp.page_master_properties_bg AS foo2, tpp.page_master_properties_data AS foo3, tpp.page_properties_style AS foo4, tpp.page_properties_bg AS foo5, group_concat(tpp.page_properties_data) AS foo6, tobj.objects_script AS foo6 FROM templates t INNER JOIN category tc ON t.category_id = tc.category_id INNER JOIN page_properties tpp ON t.templates_id = tpp.templates_id INNER JOIN objects tobj ON t.templates_id = tobj.templates_id WHERE t.templates_id = ? GROUP BY tpp.page_master_properties_style AS foo1, tpp.page_master_properties_bg AS foo2, tpp.page_master_properties_data AS foo3, tpp.page_properties_style AS foo4, tpp.page_properties_bg AS foo5 

This will group all the rows in tpp.page_properties_data together into a single row of data and separate them with commas so that you can easily explode into an array while passing through the dataset.

+4
source

Source: https://habr.com/ru/post/1434164/


All Articles