douyouqian8550 2015-10-01 14:19
浏览 53
已采纳

如何从codeigniter中获取数据库中的所有数据

I want to display the student names from db and two buttons for each students. In my code i am using ajax function.

controller

    function get_sib_filter()
    {
       $list_id= $this->input->post('id2');
       if(($list_id)==1)
       {
         $filtered_students = $this->home_model->filter_by_sibling(); 
         $new_string = "";
         foreach($filtered_students->result() as $detail)
         {
           $new_string.=$detail->applicant_first_name;
           $new_string=$new_string.'<a href="<?echo base_url();?>home/change_filter_status_green/"'.$detail->applicant_id.'" class="btn green button_style" title="Filter">Selected For Interview</a>';
           $new_string=$new_string.'<a href="<?echo base_url();?>home/change_filter_status_red/"'.$detail->applicant_id.'" class="btn red but_style" title="Rejected">Rejected</a></br>';

        }

      echo $new_string;
     }

   }

But i got the last name only(last name and two buttons)

I want list all name and all name having two buttons

Plzz give suggetions..

  • 写回答

4条回答 默认 最新

  • doufu5747 2015-10-01 14:51
    关注

    Like mentioned in the comments above, here are the issues found:

    • you never defined $new_string
    • you are overwriting $new_string
    • you are not concatenating the base_url the right way
    • Also, since you are using base_url you should be loading the URL helper in your controller ($this->load->helper('url')) or autoloading it in autoload.php

    Try this:

    $students = $filtered_students->result();
    $string = "";
    foreach ($students as $student) {
        $string .= $student->applicant_first_name . " ";;
        $string .= "<a href='" . base_url() . "home/change_filter_status_green/$student->applicant_id' class='btn green button_style' title='Filter'>Selected For Interview</a> | ";
        $string .= "<a href='" . base_url() . "home/change_filter_status_red/$student->applicant_id'' class='btn red but_style' title='Rejected'>Rejected</a><br/>";
    }
    echo $string;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?