文末有BUG提示
总结:
关于2两个关联表聚合查询返回数据个人总结。
数据请求用到max(),GROUP_CONCAT(),concat_ws(),CONCAT(),group by。
php字符串拆分用到explode()。
php将两个索引数组重组成关联数组用到array_combine()。
我这个需求和做法,纯属个人根据自己的想法和需求来的,本人不是专业程序员,自学的,目前自己还没有找到更好的方法,这里纯属个人记录,如果还有其他好用的方法,还望大家给与指点。
一、返回数据结构:
下面为接口返回的数据结构,数据来自2张表,分别为project和project_combo。
下面的数据是采用第三种方法得到的数据
"data":[
{
"id": 5,
"group_name": "年卡",
"type": "times",
"sort": null,
"tags": null,
"is_show": "Y",
"summary": null,
"group_combo": [
{
"id": "7",
"pid": "5",
"title": "年卡*1年",
"simple_title": "1年",
"group_price": "2280.00",
"price": "2280.00",
"num": "-1",
"days": "365",
"unit": "day"
},
{
"id": "8",
"pid": "5",
"title": "年*2年",
"simple_title": "2年",
"group_price": "3680.00",
"price": "3680.00",
"num": "-1",
"days": "2",
"unit": "year"
}
]
},
{
"id": 7,
"group_name": "月卡",
"type": "times",
"sort": null,
"tags": null,
"is_show": "Y",
"summary": null,
"group_combo": [
{