Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取CodeIgniter中select语句的空结果_Php_Mysql_Sql_Codeigniter - Fatal编程技术网

Php 获取CodeIgniter中select语句的空结果

Php 获取CodeIgniter中select语句的空结果,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,在这个项目中,学院必须根据两个参数——科目和分数——搜索录取的学生,我写了一个查询,但结果是空的 这是搜索候选人的控制器 public function check_search_students() { $config = array( array( 'field' =>'subject', 'label' =>

在这个项目中,学院必须根据两个参数——科目和分数——搜索录取的学生,我写了一个查询,但结果是空的

这是搜索候选人的控制器

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);
        }
     }
查看--->查看\u搜索\u学生

<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();
        }


是的,这就是问题所在,现在它运行良好。谢谢你不要投票,看我的名声:P。我是这个网站的新手
 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();
        }