Add array to Json output

0

Hello, I'm wondering how I could join this array 4 with the relationship between them. I have the page hierarchy - > post - > comments - > reply I need to associate the posts to the page, the comments to the post and the answers to the comments. The relationship between them is contained in the key. I do the separation from a select to bd where I use a left join to eliminate redundancies and perform other filters. But the intention is that it will eventually exit the endpoint all together in JSON.

    foreach ( $this->db as $key ) 
    {

        if ( strlen( $key->idpage ) > 0 )
        {
            $this->mentions_page[ $key->idpage ] = $key->pg_about;
            $this->page[$key->idpage]            = array( 'nome' => $key->pg_name, 'category' => $key->pg_category, 'link' => $key->pg_link, 'about' => $key->pg_about, 'avatar' => $key->pg_avatar );          
        }

        if ( strlen( $key->ps_message ) >0 )
        {
            $this->mentions_post[ $key->idpost ] =  $key->ps_message;
            $this->post[ $key->idpost ]          = array( 'idpage' => $key->ps_idpage, 'name' => $key->ps_message, 'date' => $key->ps_date, 'link' => $key->ps_link, 'picture' => $key->ps_picture );                 
        }

        if ( strlen( $key->cm_message ) > 0 )
        {
            $this->mentions_comment[ $key->idcomment ]     = $key->cm_message;  
            $this->author_comment[ $key->idcomment ]       = $key->cm_name_author;   
            $this->sentiment_comment_id[ $key->idcomment ] = $this->GenSentiment($key->cm_message);

            $this->comment[ $key->cm_idcomment ]           = array( 'idpost' => $key->cm_idpost, 'date' => $key->cm_date, 'link' => $key->cm_link, 'message' => $key->cm_message, 
                                                                    'user' => array( 'id' => $key->cm_id_author, 'avatar' => $key->cm_avatar_author, 'name' => $key->cm_name_author, 'gender' => '0') );
        }

        if ( strlen( $key->rp_message ) > 0 )
        {
            $this->mentions_reply[ $key->idreply ]       = $key->rp_message;
            $this->author_reply[ $key->idreply ]         = $key->rp_name_author;
            $this->sentiment_reply_id[ $key->idreply ]   = $this->GenSentiment($key->rp_message);

            $this->reply[ $key->rp_idreply ]             = array( 'idcomment' => $key->rp_idcomment, 'date' => $key->rp_date, 'link' => $key->rp_link, 'message' => $key->rp_message, 
                                                                'user' => array( 'id' => $key->rp_id_author, 'avatar' => $key->rp_avatar_author, 'name' => $key->rp_name_author, 'gender' => '0') );
        }

    }
    
asked by anonymous 26.09.2016 / 22:40

0 answers