質問

ポストおよびコメントが格納され同表に示す。する各ポストとのコメントしています:

    $posts = $this->select()->setIntegrityCheck(false)
                        ->from(array('post' => 'Posts'), array('*'))
                        ->where('post.idGroup = ' . $idGroup)
                        ->where('post.idTopic IS NULL')
                        ->order('post.date DESC')
                        ->limit($resultsPerPage, $resultsPerPage * ($page - 1))
                        ->joinLeft(array('user' => 'Users'), 'post.idUser = user.idUser', 
                            array('idUser', 'fname', 'lname', 'profileUrl', 'photoUrl'))
                        ->joinLeft(array('comment' => 'Posts'), 'comment.idTopic = post.idPost')
                        ->query()->fetchAll();

問題は、当然のことですが、そのような配列は横ばいとなり、コメントデータで上書きのデータというものを考えて、返される:

[1] => Array
    (
        [idPost] => 13
        [idTopic] => 11
        [idGroup] => 1
        [idUser] => 84
        [postContent] => Hello my name is Mud.
        [postUrl] => 13/hello-my-name-is-mud
        [postVotes] => 
        [postScore] => 
        [date] => 2009-07-21 16:39:09
        [fname] => John
        [lname] => Doe
        [profileUrl] => john-doe
        [photoUrl] => uploads/userprofiles/0/84/pic84_14
    )

このような結果になるものをつけることができます。:

    [1] => array(
            [post] => array(
                [0] => array(
                    idPost => 12,
                    postContent => This is a post...,
                    idGroup => 1
                    ...
                )
            ),
            [user] => array(
                [0] => array(
                    userName => JohnDoe
                    ...
                    )
                ),
            [comments] => array(
                [0] => array(
                    idPost => 15,
                    postContent => This is a comment...,
                    idGroup => 1
                    ...
                ),
                [1] => array(
                    idPost => 17,
                    postContent => This is another comment...,
                    idGroup => 1
                    ...
                )
            )
        )

他のヒントを他のソリューションも歓迎いたします。

感謝。

役に立ちましたか?

解決

場合は別名すべての列の上でご参加の投稿のようidPostとしてchild_idPost...など)を取得するでしょう多くの行が、親の行を列のです。私の最も近いです。/きむ、親会社からのデータの最初の行で、そのループを通じてその後の行につ多くのデータです。

その他、二つのクエリは、親会社、子どもたち。こよりも早くそれを作っている大きな結果をテーブル。

他のヒント

Zendな形式に簡単ですが、も可能です。がありますので注意してくださいお願いし、データベースサーバーをいかに作品だったので、ポストやユーザー情報の複製された各コメントとなります。詳しくは正しいことを第二の問い合わせやしょうが速くなります。しかし、私は提供できる一部のポインタに対す。

ものになると、うまく利用 Zend_Db::FETCH_NUM フェッチモード:

Array(
    [0] => Array(
        [0] => 12
        [1] =>
        [2] => 1
        [3] => 84
        [4] => This is a post...,
        [5] => 12/this-is-a-post
        [6] =>
        [7] =>
        [8] => 2009-07-21 16:39:09
        [9] => 84
        [10] => John
        [11] => Doe
        [12] => john-doe
        [13] => uploads/userprofiles/0/84/pic84_14
        [14] => 15
        [15] => 12
        [16] => 1
        [17] => 79
        [18] => This is a comment...,
        [19] =>
        [20] =>
        [21] =>
        [22] => 2009-07-21 17:40:10
    ),
    [1] => Array(
        [0] => 12
        [1] =>
        [2] => 1
        [3] => 84
        [4] => This is a post...,
        [5] => 12/this-is-a-post
        [6] =>
        [7] =>
        [8] => 2009-07-21 16:39:09
        [9] => 84
        [10] => John
        [11] => Doe
        [12] => john-doe
        [13] => uploads/userprofiles/0/84/pic84_14
        [14] => 17
        [15] => 12
        [16] => 1
        [17] => 127
        [18] => This is another comment...,
        [19] =>
        [20] =>
        [21] =>
        [22] => 2009-07-20 10:31:26
    )
)

そしてなんとかいにマッピング列番号テーブルやカラム名:

Array(
    [0] => post.idPost
    [1] => post.idTopic
    [2] => post.idGroup
    [3] => post.idUser
    [4] => post.postContent
    [5] => post.postUrl
    [6] => post.postVotes
    [7] => post.postScore
    [8] => post.date
    [9] => user.idUser
    [10] => user.fname
    [11] => user.lname
    [12] => user.profileUrl
    [13] => user.photoUrl
    [14] => comment.idPost
    [15] => comment.idTopic
    [16] => comment.idGroup
    [17] => comment.idUser
    [18] => comment.postContent
    [19] => comment.postUrl
    [20] => comment.postVotes
    [21] => comment.postScore
    [22] => comment.date
)

この部でトリッキーがテーブルの一部で強い特定のデータベースへのインタフェースなどの見所も可能です。で結ばれた結果セットは、アダプターであるとともに、"リーマン-ショックを取得するこのハッキングZendの授業が提供による独自のアダプタクラスです。によってデータベースの情報が来てから:

その他のアダプターなどで獲得するにはテーブル名は、残念ながら、

えしていましたので、同じ問題がクロスを上げの情報をブログで発信す: http://www.kintek.com.au/blog/zend-db-and-joins/

必要なものの名称各分野で独自で知られるバグを修正Zend: http://framework.zend.com/issues/browse/ZF-6421?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top