Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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_Codeigniter_Codeigniter 3_Codeigniter Database - Fatal编程技术网

Php 在选择框中动态显示值在codeigniter中不起作用

Php 在选择框中动态显示值在codeigniter中不起作用,php,mysql,codeigniter,codeigniter-3,codeigniter-database,Php,Mysql,Codeigniter,Codeigniter 3,Codeigniter Database,我正在尝试在选择框中获取值,因为dynamic不起作用 以下是我的控制器代码: public function CreateNewAsset() { $data['courselist'] = $this->Dashboard_model->getDashboardCourses(); $this->form_validation->set_error_delimiters('<div class="error">', '</div&g

我正在尝试在选择框中获取值,因为dynamic不起作用 以下是我的控制器代码:

public function CreateNewAsset() 
{
    $data['courselist'] = $this->Dashboard_model->getDashboardCourses();
    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');

    //Validating Name Field
    $this->form_validation->set_rules('topicname', 'Topicname', 'required');

   if ($this->form_validation->run() == FALSE) {
        $this->load->view('template/header');
        $this->load->view('Dashboard/CreateNewAsset');
        $this->load->view('template/footer');
    } else {

        //Setting values for tabel columns           
        $data = array(
            'courseid' => $this->input->post('courseid'),
            'topicname' => $this->input->post('topicname'),
            'refid' => $this->input->post('refid'),
            'startdate' => $this->input->post('startdate'),
            'expectedend' => $this->input->post('expectedend')
        );

        //Transfering data to Model
        $this->Dashboard_model->assetInsert($data);
        $data['message'] = 'Data Inserted Successfully';

        //Loading View
        $this->load->view('template/header');
        $this->load->view('Dashboard/CreateNewAsset', $data);
        $this->load->view('template/footer');
    }
}
公共函数CreateNewAsset()
{
$data['courselist']=$this->Dashboard_model->getDashboardCourses();
$this->form_validation->set_error_分隔符(“”,);
//验证名称字段
$this->form_validation->set_规则('topicname','topicname','required');
如果($this->form\u validation->run()==FALSE){
$this->load->view('template/header');
$this->load->view('Dashboard/CreateNewAsset');
$this->load->view('template/footer');
}否则{
//设置选项卡列的值
$data=数组(
“courseid”=>this->input->post('courseid'),
'topicname'=>this->input->post('topicname'),
“refid”=>this->input->post('refid'),
'startdate'=>this->input->post('startdate'),
'Expecteded'=>this->input->post('Expecteded')
);
//将数据传输到模型
$this->Dashboard\u model->assetInsert($data);
$data['message']='data Inserted Successfully';
//加载视图
$this->load->view('template/header');
$this->load->view('Dashboard/CreateNewAsset',$data);
$this->load->view('template/footer');
}
}
以下是我的观点:

<form action="<?php echo base_url();?>Dashboard/CreateNewAsset" method="post">
    <div class="form-row">
        <div class="col-md-3">Course:</div>
        <div class="col-md-9"> 
         <select name="courseid" class="form-control">
               <option value="0">Select Course</option>
            <?php foreach ($courselist as $course) { ?>
                <option value="<?php echo $course->id; ?>"><?php echo $course->coursename; ?></option>
            <?php } ?>
        </select>
        </div>
    </div>
</form>
像这样更改插入部分,因为u重写了
$data:

整个代码应该是这样的:

注意:确保已加载
表单验证
库和方法
getDashboardCourses
返回一些数据

公共函数CreateNewAsset()
{
$data['courselist']=$this->Dashboard_model->getDashboardCourses();
$this->form_validation->set_error_分隔符(“”,);
$this->form_validation->set_规则('topicname','topicname','required');
如果($this->form\u validation->run()==FALSE){
$this->load->view('template/header');
$this->load->view('Dashboard/CreateNewAsset',$data);
$this->load->view('template/footer');
} 
其他的
{
$insert_data=数组(
“courseid”=>this->input->post('courseid'),
'topicname'=>this->input->post('topicname'),
“refid”=>this->input->post('refid'),
'startdate'=>this->input->post('startdate'),
'Expecteded'=>this->input->post('Expecteded')
);
$this->Dashboard\u model->assetInsert($insert\u data);
$data['message']='data Inserted Successfully';
$this->load->view('template/header');
$this->load->view('Dashboard/CreateNewAsset',$data);
$this->load->view('template/footer');
}
}
您的“视图”找不到
courseList
变量

在将
courseList
传递给表单视图之前,需要将其添加到
数据数组中

例如:

数据['courseList']=$this->getCourseList();//获取行列表


在您的控制器中,我看不到您将
courselist
传递给视图,这意味着它将不存在于视图中(如果这是加载问题中HTML的控制器)。$this->load->view('Dashboard/CreateNewAsset',$data);这是我的观点,我传递了$data,对吗?是的,但您
$data
-数组不包含
课程列表。您确实在方法的顶部添加了
$data['courselist']
,但是以后添加时会覆盖该变量:
$data=array(…)
。是的,这就是为什么我不明白为什么它不在另一块上获取我的CourtSelist数据,而它是在获取我的insert$数据数组。那么,如果我想在同一个函数上获取我的courselist,解决方案是什么呢?在
else
-块中,
$insert\u data
-数组中仍然没有
courselist
。但是,这可能不是必需的,这取决于视图中发生的情况(在if和else中调用的是同一个视图)。@padeep hi我有一个疑问,可以问一下吗
  $insert_data = array(
        'courseid' => $this->input->post('courseid'),
        'topicname' => $this->input->post('topicname'),
        'refid' => $this->input->post('refid'),
        'startdate' => $this->input->post('startdate'),
        'expectedend' => $this->input->post('expectedend')
    );
    $this->Dashboard_model->assetInsert($insert_data);
public function CreateNewAsset() 
{
   $data['courselist'] = $this->Dashboard_model->getDashboardCourses();
   $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
   $this->form_validation->set_rules('topicname', 'Topicname', 'required');

   if ($this->form_validation->run() == FALSE) {
        $this->load->view('template/header');
        $this->load->view('Dashboard/CreateNewAsset',$data);
        $this->load->view('template/footer');
   } 
   else 
   {
      $insert_data = array(
            'courseid' => $this->input->post('courseid'),
            'topicname' => $this->input->post('topicname'),
            'refid' => $this->input->post('refid'),
            'startdate' => $this->input->post('startdate'),
            'expectedend' => $this->input->post('expectedend')
        );
        $this->Dashboard_model->assetInsert($insert_data);
        $data['message'] = 'Data Inserted Successfully';
        $this->load->view('template/header');
        $this->load->view('Dashboard/CreateNewAsset', $data);
        $this->load->view('template/footer');
    }
}