圖1是表1,圖2是表2.表1中的 advantage 對應(yīng)表2的 type ,以及圖2的 with_id 對應(yīng)表1的主鍵ID,也就是說,最終獲取出來的數(shù)據(jù)是這種格式:array( "id" => 1, "title" => "string", "content" => "string", "advantage" => array(6), "features" => array(4), "process" => array(7));用join寫獲取出來的數(shù)據(jù)就搞不懂該怎么去遍歷了。$res = ServiceList::alias("s") -> field("s.*") -> join("service_in_arr si", "s.id = si.with_id") -> field("si.title as title1, si.content as content1") -> select();這種寫出來的數(shù)據(jù)即圖3,表1僅1條數(shù)據(jù),表2的數(shù)據(jù)僅是表1某字段的一個數(shù)據(jù)集。若我需要按照第一種格式去獲取數(shù)據(jù),這種該怎么寫?請大神蒞臨指導,非常感謝!表1獲取的格式<code>array( "id" => 1,"title" => "string","content" => "string","advantage" => "advantage","features" => "features","process" => "process");</code>表2獲取的格式<code>array( "id" => 1,"with_id" => "string","type" => "string","title" => "string",);</code>需要的格式<code>array( "id" => 1,"title" => "string","content" => "string","advantage" => array(6),"features" => array(4),"process" => array(7));</code>
2 回答

拉風的咖菲貓
TA貢獻1995條經(jīng)驗 獲得超2個贊
如果你實在搞不懂的話,可以先不考慮聯(lián)接查詢,分兩次查詢,在遍歷第一個查詢列表中實現(xiàn)數(shù)據(jù)綁定,先達到目的再進行代碼優(yōu)化為上上選
- 2 回答
- 0 關(guān)注
- 1783 瀏覽
添加回答
舉報
0/150
提交
取消