我在數據庫笨:查詢結果劃分爲關聯數組
1.main_category字段(ID,main_name)兩個表; (ID,main_id,sub_name)調用
main_id
這裏被用於從該連接兩個表
2.sub_category字段我想獲得像以下數組
Array
(
[CCTV] => Array
(
[0] => Array
(
[id] => 1
[main_id] => 4
[name] => first
)
[1] => Array
(
[id] => 3
[main_id] => 4
[name] => second
)
[2] => Array
(
[id] => 4
[main_id] => 4
[name] => second
)
)
[Security Camera] => Array
(
[0] => Array
(
[id] => 5
[main_id] => 5
[name] => first
)
[1] => Array
(
[id] => 6
[main_id] => 5
[name] => second
)
[2] => Array
(
[id] => 7
[main_id] => 5
[name] => second
)
)
)
這裏的key
結果數組是main_name
字段,它來自main_category
表,每個鍵的關聯數組包含與條件匹配的行
where main_category.id=sub_category.main_id
我想db查詢實現上述result.is它可能與連接查詢?
你可以探討你的問題。 contorller,型號 – NomanJaved
我沒有寫任何查詢的 –
你需要用這兩個表連接查詢嗎? –