1

在我对 codeigniter 中的评论模块的回复中,我试图获得一些查询结果已经被困了大约一个星期。我肯定能够插入对评论的回复并将它们链接到正确的评论。

但是,我无法返回回复的结果。我的查询结构基于我能够显示的评论结果。

这是代码:

插入回复并尝试在控制器上提取结果:

public function insert_airwaves_comments_replies($profile_id)
    {
        //echo $profile_id;
        $this->load->model('account_model');
        $this->load->library('session');
        $this->load->helper('date');
        $user = $this->account_model->user();
        $session_id = $this->session->userdata['id'];
        $data['user'] = $user;
        $this->load->model('community_model');
        $this->load->library('form_validation');
        $submit = $this->input->post('sub_comment_reply');
        $this->load->library('session');
        $airwave = $this->community_model->get_airwave_comments($profile_id); 
        $data['airwave'] = $airwave;
        if(isset($submit))
        {
        foreach($airwave as $airwave_id)    


            //if($this->form_validation->run() == FALSE)
        //  {
            //  $data['main_content'] = 'account/profile';
            //  $this->load->view('includes/templates/main_page_template', $data);
        //  }
        //  else
            //{
                $save_data = array(
                    'airwave_id' => $airwave_id['id'],
                    'from_id' => $session_id,
                    'comment' => $this->input->post('airwaves_comments_replies'),
                    'status' => 'active',
                    'datetime' =>  date('Y-m-d H:i:s',now())
                );
                $query = $this->community_model->save_airwaves_comments_replies($profile_id,$save_data);
                $airwave_reply = $this->community_model->get_airwaves_comments_replies($profile_id); 
                $data['airwave_reply'] = $airwave_reply;
                redirect('/account/profile/'.$profile_id);
                }


        //}
    }

从模型中获取结果:

public function get_airwaves_comments_replies($profile_id) 

              {

                $session = $this->session->userdata('is_logged_in');
                $user_id= $this->session->userdata('id');



        if($profile_id == $user_id)
                {
                   $comments_query = "SELECT 
                                            awr.id AS id,
                                            awr.airwave_id AS airwave_id,
                                            awr.from_id AS from_id,
                                            awr.comment AS comment,
                                            awr.status AS status,
                                            awr.thumbsup_reply AS thumbsup_reply,
                                            awr.datetime AS datetime,
                                            u.first_name AS first_name
                                        FROM 
                                            airwaves_comments_replies awr,
                                            users u 
                                        WHERE 
                                            u.id=awr.from_id 

                                            AND awr.from_id =".$profile_id." 
                                        order by 
                                            awr.datetime 
                                        desc" ;
            }

            else
            {
                $comments_query = "SELECT awr.id AS id,
                awr.airwave_id AS airwave_id,
                awr.from_id AS from_id,
                awr.comment AS comment,
                awr.status AS status,
                awr.thumbsup_reply AS thumbsup_reply,
                awr.datetime AS datetime,
                u.first_name AS first_name FROM airwaves_comments_replies awr,users u WHERE u.id = awr.from_id AND awr.from_id =".$profile_id." order by awr.datetime desc" ;
            }




                $query = $this->db->query($comments_query);

                    if($query->num_rows() >= 1)
                    {
                       $data = $query->result_array();
                       // return whole resultset. It contains zero, one or more records
                       return $data;


                    }
                    else return false;
            }

在我的视图中显示结果:

if ($airwave_reply)
    {
        foreach ($airwave_reply as $airwave_reply_comment_row)
    { ?>
 ?>
    <?php echo $airwave_reply_comment_row['from_id']; echo "<br />"; 
   echo $airwave_reply_comment_row['first_name'];?>
<div class="response_structure_future">
    <a name="response_<?php echo $airwave_reply_comment_row['id']; ?>"></a>
    <div class="response_polaroid_future">
        <a href="">
        <img src='/styles/images/prof_thumbnail_2.jpg'/>
        </a>
    </div>
    <div class="response_body_future">
    <div class="response_arrow_future"></div>
        <div class="response_tail_future"></div>
        <div class="response_data_future">
            <div class="response_name_future">
                <a href="">
                <?php echo $airwave_reply_comment_row['first_name'];?>says...
                </a>
            </div>
            comment here
            <div class="respond_info_future">
                at <?php echo date('M d, Y',strtotime($airwave_reply_comment_row['datetime'])); ?> 
                <?php //if($auth->id == $replier->id || $auth->id == $result['ToUserID']) ?>
                <a onclick="confirmation('');"> &bull; delete</a>
                <?php  ?>
                <div id="thumb_holder">
                    <div id="thumb_report">
                        <a href="mailto:info@cysticlife.org">
                            report
                        </a>
                    </div>
                    <div  class= "thumb_counter" id="thumb_counter<?php// echo $reply['id']; ?>">
                    +<?php //echo $reply['thumbsUp_reply']; ?>
                    </div>
                    <div id="thumb_thumb">

                        <?php $comment_reply_id = $reply['id'];?>
                    <a class="myButtonLink" href="Profile.php?id=<?php //echo $prof->id; ?>" id="<?php //echo $comment_reply_id; ?>">Vote Up!</a>


                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php 
    }
}
 ?>

<a name='reply_form_<?php echo $airwave_comment_row['id']; ?>' style="clear:both"></a>
<div id='reply_to_<?php echo $airwave_comment_row['id']; ?>' class="respond_structure_future" <?php if(isset($_GET['reply_to']) && $_GET['reply_to'] == $airwave_comment_row['id']) { echo 'style="display:block;"';}else{ echo 'style="display:none;"';} ?>>
    <div class="response_polaroid_future">
        <a href="http://www.cysticlife.org/Profile.php?id=<?php// echo $auth->id; ?>">
            <img src="/styles/images/prof_thumbnail_2.jpg" />
        </a>
    </div>
    <?php                               
    echo validation_errors();
    echo form_open('community/insert_airwaves_comments_replies/'.$this->uri->segment(3));
    ?>
        <div class="respond_body_future">
            <div class="response_arrow_future"></div>
            <div class="response_tail_future"></div>
            <div class="respond_data_future">
            <?php 
            $data = array('name' => 'airwaves_comments_replies', 'id' => 'reply_to'. $airwave_comment_row['id'].'_textarea', 'class' => 'respond');
            echo form_textarea($data, set_value('airwaves_comments_replies'));
            $data = array('type' => 'hidden', 'name' => 'comment', 'value' => $airwave_comment_row['id']);
            echo form_input($data);
            ?>
            <div class="respond_nevermind">
                <a href="reply_to_<?php echo $airwave_comment_row['id']; ?>">nevermind</a>
            </div>
            <?php
            echo form_submit('sub_comment_reply', 'Reply'); 
            ?>

            </div>
        </div>
    </form>
</div>

请让我知道您可能还需要什么帮助,并提前致谢。

4

1 回答 1

1

你现在的结果是什么?

使用您显示的代码,您的控制器将评论回复插入到 foreach 循环中,但将用户重定向到

redirect('/account/profile/'.$profile_id)

我没有看到您调用视图以显示评论的任何代码,所以我认为如果没有更多解释和代码,我们将无法进一步帮助您。

于 2013-07-19T09:08:09.993 回答