我必须显示商店的产品列表。我只有一个商店 ID,我必须关联 6 个表才能获得。我使用的查询是正确地获取记录,但不是以所需的数组格式。我不知道我想要的数组格式是否可行。我的SQL如下:
SELECT DISTINCT KR.knifename,KR.id,CAT.categoryname,KR.knifecode FROM assocknives AS AK
INNER JOIN kniferegisters AS KR ON KR.id = AK.kniferegister_id
INNER JOIN categories AS CAT ON CAT.id = KR.sub_category_id
INNER JOIN stores AS STR ON STR.id = AK.store_id
INNER JOIN brands AS BRND ON BRND.id = AK.brand_id
INNER JOIN assocknifeprices AS AKP ON AKP.assocknife_id = AK.id
WHERE AK.store_id='.$storeId.' AND BRND.is_active ="1" AND STR.is_active ="1"
这给了我数组
Array
(
[0] => Array
(
[KR] => Array
(
[knifename] => xxx
[id] => xxx
[knifecode] => xxx
)
[CAT] => Array
(
[categoryname] => xxx
)
)
[1] => Array
(
[KR] => Array
(
[knifename] => xxx
[id] => xxx
[knifecode] => xxx
)
[CAT] => Array
(
[categoryname] => xxx
)
)
)
结果是正确的,但我想得到它
Array
(
[categoryname1] => Array
(
[0] => Array
(
[knifename] => xxx
[id] => xxx
[knifecode] => xxx
)
[1] => Array
(
[knifename] => xxx
[id] => xxx
[knifecode] => xxx
)
)
[categoryname2] => Array
(
[0] => Array
(
[knifename] => xxx
[id] => xxx
[knifecode] => xxx
)
[1] => Array
(
[knifename] => xxx
[id] => xxx
[knifecode] => xxx
)
)
) 对不起,如果这似乎是一件愚蠢的事情,但这种数组格式真的会帮助我的事业。谢谢大家的关注。