1
我有兩個表,一個主表,一個支持主表,非常非常類似於WordPress的帖子和posts_meta。合併元表與主表
主表:
ID 標題, 內容
id | title | content
1 | one | content one
2 | two | content two
元表:
ID ITEM_ID 鍵 值
id | item_id | key | value
1 | 1 | template | single
2 | 1 | group | top
1 | 2 | template | page
2 | 2 | group | bottom
最後,我的目標是將數據從主表中取出,並與元表合併。例如:
$data = array(
array(
'id' => 1,
'title' => 'one',
'content' => 'content one',
'template' => 'single',
'group' => 'top'
),
array(
'id' => 2,
'title' => 'two',
'content' => 'content two',
'template' => 'page',
'group' => 'bottom'
)
);
什麼是最好的方式來實現這種方式,預成型好?
我正在使用PDO連接到我的數據庫,以及我現在如何做,我首先查詢第一個表上的數據,然後對於每個結果,我查詢元表,我使用這個準備好的語句,因爲它被認爲是快速的,但即便如此,它也損害了我的劇本的表現。
謝謝
這聽起來像一個很好的solutuion,你會怎麼建議我合併?我現在有一個與元數據數組,並不能想到一個有效的方式合併,謝謝 – johnsardine
花費的答案。你可以使用引用來加速。 – fsw
謝謝你的時間和幫助,這工作完美 – johnsardine