Php 通过使用Codeigniter从mysql数据库获取值,在CSV文件中创建下拉列表
我正在尝试将csv文件导入我的MySql数据库。在我的页面中,我将提供一个示例csv文件供用户下载,在该csv文件中,用户需要输入相应的值,然后将其上载。这些值将被插入到表中。但是,如果我尝试将csv文件插入到有外键的表中,我希望csv中的相应列表供用户从主表中选择其相应的名称。下面是我需要导入csv的数据库 如您所见,parent_id是子类别表的id。我想在csv内的下拉列表中显示子类别表的标题 预期输出与下面给定的演示图像类似 我在Codeigniter中这样做 控制器代码Php 通过使用Codeigniter从mysql数据库获取值,在CSV文件中创建下拉列表,php,mysql,codeigniter,csv,import-from-excel,Php,Mysql,Codeigniter,Csv,Import From Excel,我正在尝试将csv文件导入我的MySql数据库。在我的页面中,我将提供一个示例csv文件供用户下载,在该csv文件中,用户需要输入相应的值,然后将其上载。这些值将被插入到表中。但是,如果我尝试将csv文件插入到有外键的表中,我希望csv中的相应列表供用户从主表中选择其相应的名称。下面是我需要导入csv的数据库 如您所见,parent_id是子类别表的id。我想在csv内的下拉列表中显示子类别表的标题 预期输出与下面给定的演示图像类似 我在Codeigniter中这样做 控制器代码
foreach ($csv_array as $row) {
$insert_data1 = array(
'parent_id'=>$row['Subcategory'],
'name' => $row['Name'],
'phone'=>$row['Phone'],
'mobile'=>$row['Mobile'],
'work_hr_from'=>$row['Work_hr_from'],
'work_hr_to'=>$row['Work_hr_to'],
'work_days'=>$row['Work_days'],
'address'=>$row['Address'],
'city_id'=>$row['City'],
'email'=>$row['Email'],
'website'=>$row['Website'],
'gmap_lat'=>$row['Gmap_latitude'],
'gmap_lng'=>$row['Gmap_longitude'],
'fax'=>$row['Fax'],
'start_year'=>$row['Start_year'],
);
$table ='item';
$st_id = $this->excel_data_insert_model->add_excel_details($insert_data1);
}
public function add_excel_details($data_user){
$this->db->insert('item', $data_user);
}
查看代码
foreach ($csv_array as $row) {
$insert_data1 = array(
'parent_id'=>$row['Subcategory'],
'name' => $row['Name'],
'phone'=>$row['Phone'],
'mobile'=>$row['Mobile'],
'work_hr_from'=>$row['Work_hr_from'],
'work_hr_to'=>$row['Work_hr_to'],
'work_days'=>$row['Work_days'],
'address'=>$row['Address'],
'city_id'=>$row['City'],
'email'=>$row['Email'],
'website'=>$row['Website'],
'gmap_lat'=>$row['Gmap_latitude'],
'gmap_lng'=>$row['Gmap_longitude'],
'fax'=>$row['Fax'],
'start_year'=>$row['Start_year'],
);
$table ='item';
$st_id = $this->excel_data_insert_model->add_excel_details($insert_data1);
}
public function add_excel_details($data_user){
$this->db->insert('item', $data_user);
}
下载示例csv的代码
<a href="#" data-toggle="popover" title="Excel Format : <a href='<?php echo base_url(); ?>uploads/excel/formatcsv.csv'><i class='fa fa-download'></i></a>" data-content="" data-html="true">Download Format</a>
提前谢谢