Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.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数据库故障_Php_Mysql_Database_Codeigniter - Fatal编程技术网

Php Codeigniter数据库故障

Php Codeigniter数据库故障,php,mysql,database,codeigniter,Php,Mysql,Database,Codeigniter,问题是当我使用这个代码时 在我的车型中: public function get_all_subject_tasks(){ $this->db->select('*'); $this->db->from('task'); $this->db->where("user_id",$this->session->userdata('user_id')); $this->db->order_by("task_id", "desc");

问题是当我使用这个代码时

在我的车型中

public function get_all_subject_tasks(){
$this->db->select('*');
$this->db->from('task'); 
$this->db->where("user_id",$this->session->userdata('user_id'));  
$this->db->order_by("task_id", "desc");    
$query_result=$this->db->get();
$result=$query_result->result();
return $result;
}                    
在我的控制器中

public function subjects($t,$action=""){
        $data=array();
        $data['subject_tasks']=$this->Schoolmodel->get_all_subject_tasks($t);
        if($action=='asyn'){
          $this->load->view('theme/task',$data);
        }else{    
          $this->load->view('theme/include/header');
        $this->load->view('theme/include/school_sidebar');
          $this->load->view('theme/task',$data);
          $this->load->view('theme/include/footer');
        }
    }        
在我的php页面中

<div class="panel-body">
       <table id="teacher_table" class="table table-striped table-bordered table-condensed">
        <th>Name</th><th><?php get_phrase('teacher_email') ?></th><th width="110"><?php get_phrase('action') ?></th>
       <?php foreach($subject_tasks as $list){ ?>
        <tr>
        <td class="task_name"><?php echo $list->task_name ?></td>
        <td class="task_desc"><?php echo $list->task_desc ?></td>
        </tr>
       <?php } ?>
        </table>
    </div>

名称
我得到数据库中的所有任务,没有任何主题过滤器

所以我的问题是 如何使页面根据任务所在的主题响应任务


下面是我如何设置我的数据库结构的

  • 受试者id
  • 任务id
  • 任务名称
  • 任务描述
  • 用户id
  • 其中subject\u id是插入任务的主题的id。

    
    
    <?php 
    
    // your model
    
    public function getTask($subject_id)
    {
        $result = $this->db
            ->where("subject_id", $subject_id) // !!!
            ->where("user_id", $this->session->userdata('user_id')) // !!!
            ->order_by("task_id", "desc")
            ->get('tasks');
    
        return $result->num_rows() > 0 ?
            $result->result() : false;
    }
    
    // your class
    
    class School extends CI_Controller {
    
        public function __construct() {
            parent::__construct();
            if($this->session->userdata('logged_in')==FALSE){
                redirect('User');
            }
            $this->load->database();
            $this->load->model('Schoolmodel');
            $this->load->library('form_validation');
        }
    
        public function subjects($subject_id,$action=""){
            $data=array();
            $data['subject_tasks'] = $this->Schoolmodel->getTask($subject_id);
            if($action=='asyn'){
                $this->load->view('theme/task',$data);
            }else{
                $this->load->view('theme/include/header');
                $this->load->view('theme/include/school_sidebar');
                $this->load->view('theme/task',$data);
                $this->load->view('theme/include/footer');
            }
        }
    
    }
    
    ?>
    
    // your view
    
        <div class="panel-body">
               <table id="teacher_table" class="table table-striped table-bordered table-condensed">
                <th>Name</th><th><?php get_phrase('teacher_email') ?></th><th width="110"><?php get_phrase('action') ?></th>
        <?php if(false !== $subject_tasks) { foreach($subject_tasks as $list){ ?>
            <tr>
                <td class="task_name"><?php echo $list->task_name ?></td>
                <td class="task_desc"><?php echo $list->task_desc ?></td>
            </tr>
        <?php } } ?>
        </table>
        </div>
    
    //你的观点 名称
    这是行不通的:

    $this->db->where("subject_id",$subject_id AND "user_id",$this->session->userdata('user_id'));  
    
    From:多次调用
    ,其中
    将导致

    $this->db->where("subject_id", $subject_id);
    $this->db->where("user_id", $this->session->userdata('user_id'));  
    

    你现在有什么问题?
    where
    内部模型不正确。我的问题是,我只希望在任务页面上显示某个主题中的任务。如何更正模型中的“where”代码?是否出现错误或显示所有任务?路由是如何配置的?我根本没有得到任何显示,没有显示数据库中的数据。这是链接的外观。您需要首先找出问题所在。如果要选择所有字段,不需要使用->选择(*)。您可以使用->获取('table')而不是->从('table')和->获取(),最好使用方法链接:)->met1()->met2()->…谢谢@Amir的帮助。