gpt4 book ai didi

php - 在 CodeIgniter 中获取 select 语句的空结果

转载 作者:行者123 更新时间:2023-11-29 23:19:37 25 4
gpt4 key购买 nike

在这个项目中,大学必须根据两个参数主题和分数来搜索被录取的学生我已经编写了查询,但我得到了空结果

这是搜索候选者的 Controller

public function check_search_students()
{
$config = array(
array(
'field' =>'subject',
'label' =>'Subject',
'rules' =>'required|trim'
),
array(
'field' =>'mark',
'label' =>'Mark',
'rules' =>'is_natural'
)
);
$this->form_validation->set_error_delimiters('<font color = "red">','</font>');
$this->form_validation->set_rules($config);
if($this->form_validation->run()===False)
{
$this->search_students(); // another function
}
else
{
$collegeid=$this->session->userdata('id');
$info['name'] = $this->college_model->get_student_name();
$info['search_student']=$this->college_model->search($collegeid);
$this->load->view('employer/view_search_students',$info);
}
}

示范大学模型

public function search($collegeid)
{

$title = $this->input->post('subject');
$mark = $this->input->post('mark');
$y=0;
if($mark==0)
{
$query=$this->db->query('SELECT s.name,s.age,p.sub_title ,s.mark
FROM applied_subs ae, student s, post_subjects p
WHERE ae.college_id=? and ae.student_id = s.id
AND p.id=ae.sub_id AND p.sub_title = "$title" ',
array($collegeid)
);
return $query->result_array();
}
else
{
$query=$this->db->query('SELECT s.name,s.age,p.sub_title ,s.mark
FROM applied_subs ae, student s, post_subjects p
WHERE ae.college_id=? and ae.student_id = s.id
AND p.id=ae.sub_id AND p.sub_title = "$title" AND p.mark="$mark"',
array($collegeid)
);
return $query->result_array();
}
}

查看--->view_search_students

<table>
<tr>
<th> Name </th>
<th> Mark </th>
</tr>
<?php foreach($search_student as $value): ?>
<tr>
<td> <?php echo $value['name'] ?> </td>
<td> <?php echo $value['mark'] ?> </td>
</tr>
<?php endforeach ?>
</table>

最佳答案

你搞乱了单引号和双引号。

您需要在 SQL 中的值周围添加单引号,而不是添加双引号。

这就是问题所在。

请检查以下内容:

改变

 if($mark==0)
{
$query=$this->db->query('SELECT s.name,s.age,p.sub_title ,s.mark
FROM applied_subs ae, student s, post_subjects p
WHERE ae.college_id=? and ae.student_id = s.id
AND p.id=ae.sub_id AND p.sub_title = "$title" ',
array($collegeid)
);
return $query->result_array();
}
else
{
$query=$this->db->query('SELECT s.name,s.age,p.sub_title ,s.mark
FROM applied_subs ae, student s, post_subjects p
WHERE ae.college_id=? and ae.student_id = s.id
AND p.id=ae.sub_id AND p.sub_title = "$title" AND p.mark="$mark"',
array($collegeid)
);
return $query->result_array();
}

 if($mark==0)
{
$query=$this->db->query("SELECT s.name,s.age,p.sub_title ,s.mark
FROM applied_subs ae, student s, post_subjects p
WHERE ae.college_id=? and ae.student_id = s.id
AND p.id=ae.sub_id AND p.sub_title = '$title' ",
array($collegeid)
);
return $query->result_array();
}
else
{
$query=$this->db->query("SELECT s.name,s.age,p.sub_title ,s.mark
FROM applied_subs ae, student s, post_subjects p
WHERE ae.college_id=? and ae.student_id = s.id
AND p.id=ae.sub_id AND p.sub_title = '$title' AND p.mark='$mark'",
array($collegeid)
);
return $query->result_array();
}

关于php - 在 CodeIgniter 中获取 select 语句的空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27438662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com