Php 如何在codeigniter中从数据库获取所有数据
我想显示db中的学生姓名以及每个学生的两个按钮。 在我的代码中,我使用的是ajax函数 控制器Php 如何在codeigniter中从数据库获取所有数据,php,ajax,codeigniter,Php,Ajax,Codeigniter,我想显示db中的学生姓名以及每个学生的两个按钮。 在我的代码中,我使用的是ajax函数 控制器 function get_sib_filter() { $list_id= $this->input->post('id2'); if(($list_id)==1) { $filtered_students = $this->home_model->filter_by_sibling();
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;
}
}
函数get\u sib\u filter()
{
$list_id=$this->input->post('id2');
if(($list_id)==1)
{
$filtered_students=$this->home_model->filter_by_sibling();
$new_string=“”;
foreach($detail)$filtered\u students->result()作为$detail)
{
$new\u string.=$detail->applicator\u first\u name;
$new_string=$new_string'';
$new_string=$new_string'.';
}
echo$new_字符串;
}
}
但我只知道姓(姓和两个按钮)
我想列出所有的名字和所有有两个按钮的名字
请给出建议。您正在覆盖此处的字符串。请按如下所示进行一些更改
$new_string = ""; // Define $new_string..
foreach($filtered_students->result() as $detail){
$new_string.=$detail->applicant_first_name;
$new_string.='<a href="'.base_url().'home/change_filter_status_green/"'.$detail->applicant_id.'" class="btn green button_style" title="Filter">Selected For Interview</a>';
$new_string.='<a href="'.base_url().'home/change_filter_status_red/"'.$detail->applicant_id.'" class="btn red but_style" title="Rejected">Rejected</a><br />';
}
$new_string=”“;//定义$new\u字符串。。
foreach($detail)$filtered\u students->result()作为$detail){
$new\u string.=$detail->applicator\u first\u name;
$new_字符串='';
$new_string.='
';
}
还要确保您从这个变量中得到了什么:$filtered\u students
。
您可以通过
print\r($filtered\u students)检查它代码>与上面的评论中提到的一样,以下是发现的问题:
- 您从未定义过
$new\u字符串
- 您正在覆盖
$new\u字符串
- 您没有以正确的方式连接
base\u url
- 另外,由于您使用的是
base\u url
,因此应该在控制器中加载url帮助程序($this->load->helper('url')
),或者在autoload.php中自动加载它
试试这个:
$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;
$students=$filtered_students->result();
$string=“”;
foreach($student作为$student){
$string.=$student->applicator_first_name.“;;
$string.=“|”;
$string.=“
”;
}
echo$字符串;
请尝试以下代码:
function get_sib_filter()
{
$list_id= $this->input->post('id2');
if($list_id == 1)
{
$filtered_students = $this->home_model->filter_by_sibling();
$new_string = "";
$count = 0;
foreach($filtered_students->result() as $detail)
{
if($count == 0){
$new_string = "<a href='".base_url('home/change_filter_status_green/').$detail->applicant_id."' class='btn green button_style' title='Filter'>Selected For Interview</a><a href='".base_url('home/change_filter_status_red').$detail->applicant_id."' class='btn red but_style title='Rejected'>Rejected</a>";
$count++;
}else{
$new_string .= $new_string."<a href='".base_url('home/change_filter_status_green/').$detail->applicant_id."' class='btn green button_style' title='Filter'>Selected For Interview</a><a href='".base_url('home/change_filter_status_red').$detail->applicant_id."' class='btn red but_style title='Rejected'>Rejected</a>";
}
}
echo $new_string;
}
函数get\u sib\u filter()
{
$list_id=$this->input->post('id2');
如果($list_id==1)
{
$filtered_students=$this->home_model->filter_by_sibling();
$new_string=“”;
$count=0;
foreach($detail)$filtered\u students->result()作为$detail)
{
如果($count==0){
$new_string=“”;
$count++;
}否则{
$new_string.=$new_string.“;
}
}
echo$new_字符串;
}
}如下更改您的型号:
function filter_by_sibling()
{
$this->db->select('applicant_id,applicant_first_name');
$this->db->from('student_application');
$this->db->order_by('sib_count','desc');
$result = $this->db->get()->result_array();
return $result;
}
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 as $detail)
{
$new_string .=$detail['applicant_first_name'];
$new_string .='<a href="'.base_url().'home/change_filter_status_green/'.$detail['applicant_id'].'" class="btn green button_style" title="Filter">Selected For Interview</a>';
$new_string .='<a href="'.base_url().'home/change_filter_status_red/'.$detail['applicant_id'].'" class="btn red but_style" title="Rejected">Rejected</a><br />';
}
echo $new_string;
}
}
按如下方式修改控制器功能:
function filter_by_sibling()
{
$this->db->select('applicant_id,applicant_first_name');
$this->db->from('student_application');
$this->db->order_by('sib_count','desc');
$result = $this->db->get()->result_array();
return $result;
}
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 as $detail)
{
$new_string .=$detail['applicant_first_name'];
$new_string .='<a href="'.base_url().'home/change_filter_status_green/'.$detail['applicant_id'].'" class="btn green button_style" title="Filter">Selected For Interview</a>';
$new_string .='<a href="'.base_url().'home/change_filter_status_red/'.$detail['applicant_id'].'" class="btn red but_style" title="Rejected">Rejected</a><br />';
}
echo $new_string;
}
}
函数get\u sib\u filter()
{
$list_id=$this->input->post('id2');
if(($list_id)==1)
{
$filtered_students=$this->home_model->filter_by_sibling();
$new_string=“”;
foreach($detail)
{
$new_string.=$detail['applicator_first_name'];
$new_字符串='';
$new_string.='
';
}
echo$new_字符串;
}
}
你为什么要写
而不是
?你的意见是什么时候定义了$new\u string
?如果我看不到你在代码中的任何地方设置姓氏,你是如何得到学生的姓氏的?@Rose这不是一个观点,这是一个问题。这些天我经常看到
,没有人能告诉我他们为什么要这么做!尝试此操作..现在显示所有名称和按钮..但按钮链接不起作用,显示一些错误页面此:“当我单击按钮时,它显示“不允许的关键字符”现在没有列出任何内容名称不显示?如何将其保存在数据库中?若不将链接分组,请在第一个a
后面放置空格和分隔符
,我已将其包含在我的答案中。我理解,但我需要了解您的数据库表结构。你能提供吗?让我们。非常感谢。我在按钮上找到了一些设计问题,否则好的,谢谢