Php 从下拉列表中选择的值将与excel工作表dat一起插入数据库
在下面的代码中,我放置了控制器、模型和视图。在其中,我从excel中获得了3列nim、nama、ALMAT和下拉列表中的考试名称,以插入到db中。现在我放置了一个下拉列表,将从考试课程表中选择的考试名称插入到db中。请帮助我解决这个问题。 控制器:Php 从下拉列表中选择的值将与excel工作表dat一起插入数据库,php,codeigniter,Php,Codeigniter,在下面的代码中,我放置了控制器、模型和视图。在其中,我从excel中获得了3列nim、nama、ALMAT和下拉列表中的考试名称,以插入到db中。现在我放置了一个下拉列表,将从考试课程表中选择的考试名称插入到db中。请帮助我解决这个问题。 控制器: public function index() { //echo "inside form upload"; $data = array(); //$college_name = $this-&
public function index()
{
//echo "inside form upload";
$data = array();
//$college_name = $this->session->userdata('college_name');
if($query = $this->import_model->get_exam_data())
{
$data['exam_data'] = $query;
}
//$this->load->view('student_view', $data);
$this->load->view('form_upload',$data);
}
public function upload()
{
$this->load->helper('file');
//echo "inside after load helper </br>";
$config['upload_path'] = './upload/';
//echo $config['upload_path'] ;
// echo "inside after upload path </br>";
$config['allowed_types'] = 'xls';
//echo "allowed_types </br>";
$this->load->library('upload', $config);
$result=$this->upload->do_upload('file');
//echo $result;
if ( $this->upload->do_upload('file'))
{
//echo "inside else upload </br>";
$data = array('error' => false);
$upload = $this->upload->data();
$this->load->library('excel_reader');
$this->excel_reader->setOutputEncoding('CP1251');
$file = $upload['full_path'];
$this->excel_reader->read($file);
$data = $this->excel_reader->sheets[0];
$excel_data = Array();
for ($i = 1; $i <= $data['numRows']; $i++)
{
if($data['cells'][$i][1] == '') break;
$excel_data[$i-1]['nim'] = $data['cells'][$i][1];
$excel_data[$i-1]['nama'] = $data['cells'][$i][2];
$excel_data[$i-1]['alamat'] = $data['cells'][$i][3];
}
delete_files($upload['file_path']);
$this->import_model->upload_data($excel_data);
redirect('index.php/success/');
}
}
}
公共功能索引()
{
//回显“内表上传”;
$data=array();
//$college\u name=$this->session->userdata('college\u name');
如果($query=$this->import\u model->get\u test\u data())
{
$data['EXAME_data']=$query;
}
//$this->load->view('student_view',$data);
$this->load->view('form_upload',$data);
}
公共函数上传()
{
$this->load->helper('file');
//回显“加载辅助对象后的内部”;
$config['upload_path']='./upload/';
//echo$config['upload_path'];
//回显“上传路径后的内部”;
$config['allowed_types']='xls';
//回显“允许的类型”;
$this->load->library('upload',$config);
$result=$this->upload->do_upload('file');
//回声$结果;
如果($this->upload->do_upload('file'))
{
//echo“内部其他上传”;
$data=array('error'=>false);
$upload=$this->upload->data();
$this->load->library('excel_reader');
$this->excel_reader->setoutpuntencoding('CP1251');
$file=$upload['full_path'];
$this->excel\u reader->read($file);
$data=$this->excel\u reader->sheets[0];
$excel_data=Array();
对于($i=1;$i导入\u模型->上传\u数据($excel\u数据);
重定向('index.php/success/');
}
}
}
型号:
function get_exam_data()
{
$this->db->distinct();
$this->db->select("CONCAT(exam_name) AS fullexamname", FALSE);//this will concat the value
//$this->db->where('college_name',$college_name);
$query = $this->db->get('examcourse');
$this->db->insert('mahasiswa', $data);
return $query->result();
}
public function upload_data($excel_data)
{
for($i = 1; $i < count($excel_data); $i++)
{
if( ! $this->is_exist($excel_data[$i]['nim']) == TRUE)
{
$data = array(
'nim' => $excel_data[$i]['nim'],
'nama' => $excel_data[$i]['nama'],
'alamat' => $excel_data[$i]['alamat']
);
$this->db->insert('mahasiswa', $data);
}
else
{
$data = array(
'nama' => $excel_data[$i]['nama'],
'alamat' => $excel_data[$i]['alamat']
);
$this->db->where('nim', $excel_data[$i]['nim']);
$this->db->update('mahasiswa', $data);
}
}
函数获取检查数据()
{
$this->db->distinct();
$this->db->select(“CONCAT(考试名称)为fullexamname”,FALSE);//这将对值进行CONCAT
//$this->db->where('college\u name',$college\u name);
$query=$this->db->get('examcourse');
$this->db->insert('mahasiswa',$data);
返回$query->result();
}
公共函数上传数据($excel\u数据)
{
对于($i=1;$iis_exist($excel_data[$i]['nim'])==TRUE)
{
$data=数组(
“nim”=>$excel_数据[$i]['nim'],
“nama”=>$excel_数据[$i]['nama'],
'alamat'=>$excel_数据[$i]['alamat']
);
$this->db->insert('mahasiswa',$data);
}
其他的
{
$data=数组(
“nama”=>$excel_数据[$i]['nama'],
'alamat'=>$excel_数据[$i]['alamat']
);
$this->db->where('nim',$excel_data[$i]['nim']);
$this->db->update('mahasiswa',$data);
}
}
视图:
所选的考试名称将与excel数据一起插入数据库请澄清错误-您有错误,您的数据未插入数据库或什么?您有什么错误?所选的下拉列表值未与excel数据一起插入数据库您在哪里将考试名称
添加到$excel\u数据
?我不知道在哪里在excel数据中输入数据的步骤
<div id="body">
<form action="http://localhost/CodeIgniter/index.php/import/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data"> <?php
$data = array();
$data["Select Exam Name"] = "Select Exam Name";
foreach ($exam_data as $row)
{
$data[$row->fullexamname] = $row->fullexamname;
}
echo form_dropdown('exam_name', $data, 'small', 'class="dropdown_class" id="exam_name_id" onChange="get_subjectcodedetails()"');
?>
<div id="ssubject_code">
<label for="file">Browse File</label> <br>
<input type="file" name="file" value="Browse File"> <br>
<input type="submit" name="button" value="Import">
</form> </div>
}