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 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用