私は2つのテーブルを持っていcontent
ますtheme
. theme
テーブルの行ごとに取得する必要がある行がいくつかありcontent
ます。これは、PDO と、LEFT JOIN
. 出力配列は、テーマ ファイル (以下) の出現ごとに 1 つの配列を提供します。
contentID
配列を再編成して、一致する各テーマ ファイルを含む配列内の配列を1 つの配列として取得するようにします。
アイデア$content=>'theme'['logo']
は、一致するテーマ ファイルのいずれかの値を取得するようなものです。
これはどのように行われますか。
array(
array (
contentID => 1,
title => 'test',
subtitle = 'a description',
themeID => 1,
theme_file => 'navigation'
)
array (
contentID => 1,
title => 'test',
subtitle = 'a description',
themeID => 2,
theme_file => 'logo'
)
)
リクエストに応じて、追加のコードを追加しました。実際には、相互にネストしたい3つのテーブルがありますが、他の人に役立つ質問をするために、2のままにしました。これは、役立つ場合のmySQLクエリです。
SELECT *
FROM content
LEFT JOIN content_theme ON content.contentID = content_theme.contentID
LEFT JOIN theme ON theme.themeID = content_theme.themeID
OR theme.default =1
LEFT JOIN theme_meta ON theme.themeID = theme_meta.themeID
WHERE content.contentID = 9
ORDER BY theme.default DESC
content
したがって、各行が一致するすべての行をネストしtheme
、これらのtheme
各行が一致するtheme_meta
各行をネストすることが意図されています。
データベースからの生の出力:
Array
(
[0] => Array
(
[contentID] =>
[0] => 4
[type] => page
[1] => page
[type_alts] =>
[2] =>
[url] => about
[3] => about
[title] => About
[4] => About
[subtitle] =>
[5] =>
[online] => 1
[6] => 1
[req] => 0
[7] => 0
[pos] => 0
[8] => 0
[parent] => 0
[9] => 0
[content_theme_ID] =>
[10] =>
[11] =>
[themeID] => 2
[12] =>
[13] => 2
[theme_type] => general
[14] => general
[theme_file] => logo
[15] => logo
[theme_default] => 1
[16] => 1
[theme_title] => MD Group
[17] => MD Group
[18] => 2
[field] => src
[19] => src
[value] => uploads/img/murphey-dines-group-logo.png
[20] => uploads/img/murphey-dines-group-logo.png
)
[1] => Array
(
[contentID] =>
[0] => 4
[type] => page
[1] => page
[type_alts] =>
[2] =>
[url] => about
[3] => about
[title] => About
[4] => About
[subtitle] =>
[5] =>
[online] => 1
[6] => 1
[req] => 0
[7] => 0
[pos] => 0
[8] => 0
[parent] => 0
[9] => 0
[content_theme_ID] =>
[10] =>
[11] =>
[themeID] => 2
[12] =>
[13] => 2
[theme_type] => general
[14] => general
[theme_file] => logo
[15] => logo
[theme_default] => 1
[16] => 1
[theme_title] => MD Group
[17] => MD Group
[18] => 2
[field] => title
[19] => title
[value] => murphey dines Group
[20] => murphey dines Group
)
[2] => Array
(
[contentID] =>
[0] => 4
[type] => page
[1] => page
[type_alts] =>
[2] =>
[url] => about
[3] => about
[title] => About
[4] => About
[subtitle] =>
[5] =>
[online] => 1
[6] => 1
[req] => 0
[7] => 0
[pos] => 0
[8] => 0
[parent] => 0
[9] => 0
[content_theme_ID] =>
[10] =>
[11] =>
[themeID] =>
[12] =>
[13] => 7
[theme_type] => general
[14] => general
[theme_file] => navigation
[15] => navigation
[theme_default] => 1
[16] => 1
[theme_title] => Main Navigation
[17] => Main Navigation
[18] =>
[field] =>
[19] =>
[value] =>
[20] =>
)
)