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条)

报告相同问题?

悬赏问题

  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面