这似乎是一个重复的问题,但我的问题却有些不同。我试图从一个表中检索数据,通过下拉列表在表单中显示我已成功实现,唯一的问题是检索是作为一个数组完成的,我现在要保存检索到的数据另一张桌子。可能吗?以及如何去做?提前致谢: 部分推荐区域:codeigniter database moving to another table @Daniel 这是我的代码:controller
function insert(){
$data['content'] = 'back/buses/insert';
$data['idnos'] = $this->owners_model->selectownerid();
$this->load->view('include/template_back', $data);
}
function insert_bus_info(){
$this->form_validation->set_rules('bus_reg','Bus Registration','required');
// $this->form_validation->set_rules('idno', 'Identification/Passport No', 'required|xss_clean');
$this->form_validation->set_rules('bus_make','Bus Make','required');
// $this->form_validation->set_rules('bus_model','Bus Model','required');
$this->form_validation->set_rules('no_of_seats','Number of Seats','required');
$this->form_validation->set_rules('bus_chasisno','Chasis Number','required');
$this->form_validation->set_rules('bus_engineno','Engine Number','required');
$this->form_validation->set_rules('year_of_manufacture','Year of Manufacture','required');
$this->form_validation->set_rules('date_of_purchase','Date of Purchase','required');
if($this->form_validation->run()==FALSE)
{
$this->load->view('include/header_back');
$this->load->view('back/buses/insert');
$this->load->view('include/footer_back');
}
else
{
$bus_reg = $this->input->post('bus_reg');
$idno = $this->input->post($row['idno']);
$bus_make = $this->input->post('bus_make');
$bus_model = $this->input->post('bus_model');
$no_of_seats = $this->input->post('no_of_seats');
$bus_chasisno = $this->input->post('bus_chasisno');
$bus_engineno = $this->input->post('bus_engineno');
$year_of_manufacture = $this->input->post('year_of_manufacture');
$date_of_purchase = $this->input->post('date_of_purchase');
$this->buses_model->insert_bus($bus_reg,$idno,$bus_make,$bus_model,$no_of_seats,$bus_chasisno,$bus_engineno,$year_of_manufacture,$date_of_purchase);
// $this->do_upload_form();
//redirect('buses/ do_upload_form','refresh');
}
}
型号:
function selectownerid(){
$query = $this->db->query('SELECT idno,username FROM owner_details');
return $query->result_array();
}
function buseslist(){
$query = $this->db->get('bus_details');
if ($query->num_rows() > 0) {
return $query->result_array();
}
}
function insert_bus($bus_reg,$idno,$bus_make,$bus_model,$no_of_seats,$bus_chasisno,$bus_engineno,$year_of_manufacture,$date_of_purchase){
$query = "INSERT INTO bus_details(bus_reg,idno,bus_make,bus_model,no_of_seats,bus_chasisno,bus_engineno,year_of_manufacture,date_of_purchase)
VALUES (?,?,?,?,?,?,?,?,?)";
$this->db->query($query,array($bus_reg,$idno,$bus_make,$bus_model,$no_of_seats,$bus_chasisno,$bus_engineno,$year_of_manufacture,$date_of_purchase));
}
function edit_bus($bus_reg){
$this->db->where('bus_reg',$bus_reg);
$query=$this->db->get('bus_details');
return $query->row();
}
查看:
<?php echo form_open('buses/insert_bus_info', array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data')); ?>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
<a href="#" class="panel-close">×</a>
<a href="#" class="minimize">−</a>
</div>
<h4 class="panel-title">Bus Details</h4>
<p>Please, Insert the details here below...</p>
</div>
<div class="panel-body panel-body-nopadding">
<!--Bus registration-->
<div class="form-group">
<label class="col-sm-4 control-label">Bus Registration</label>
<div class="col-sm-8">
<input type="text" name="bus_reg" class="form-control" />
</div>
<?php echo form_error('bus_reg');?>
</div>
<!--IDno-->
<div class="form-group">
<label class="col-sm-4 control-label">Identification/Passport No</label>
<div class="col-sm-8">
<select class="form-control mb15" placeholder="Identification/Passport No">
<?php foreach($idnos as $row){
echo '<option value="'.$row['idno'].'">'.$row['username'].'</option>';
}
?>
</select>
</div>
<?php echo form_error('idno');?>
</div>
<!--Bus Make-->
<div class="form-group">
<label class="col-sm-4 control-label">Bus Make</label>
<div class="col-sm-8">
<select class="form-control mb15" id="bus_make" name="bus_make" placeholder="Bus Make">
<option value="">All Buses</option>
<option value="Isuzu">Isuzu</option>
<option value="Nissan Diesel">Nissan Diesel</option>
<option value="Mitsubishi">Mitsubishi</option>
<option value="Hino">Hino</option>
</select>
<!-- <input type="text" class="form-control" /> -->
</div>
<?php echo form_error('bus_make');?>
</div>
<!--Bus Model-->
<div class="form-group">
<label class="col-sm-4 control-label">Bus Model</label>
<div class="col-sm-8">
<select class="form-control mb15" id="bus_model" name="bus_model" placeholder="Bus Model">
<option></option>
</select>
<!-- <input type="text" name="bus_model" class="form-control" /> -->
</div>
<?php echo form_error('bus_model');?>
</div>
<span id="optionstore" style="display:none;"></span>
<!--Middle Name-->
<div class="form-group">
<label class="col-sm-4 control-label">Number of Seats</label>
<div class="col-sm-8">
<input type="text" name="no_of_seats" class="form-control" />
</div>
<?php echo form_error('no_of_seats');?>
</div>
<!--Owner Address-->
<div class="form-group">
<label class="col-sm-4 control-label">Bus Chasis Number:</label>
<div class="col-sm-8">
<input type="text" name="bus_chasisno" class="form-control" />
<?php echo form_error('bus_chasisno');?>
</div>
</div>
<!--Owner Email-->
<div class="form-group">
<label class="col-sm-4 control-label">Bus Engine Number:</label>
<div class="col-sm-8">
<input type="text" name="bus_engineno" class="form-control" />
</div>
<?php echo form_error('bus_engineno');?>
</div>
<!--Owner Phone Number-->
<div class="form-group">
<label class="col-sm-4 control-label">Year of Manufacture</label>
<div class="col-sm-8">
<input type="text" name="year_of_manufacture" id="yearpicker" class="form-control" />
</div>
<?php echo form_error('year_of_manufacture');?>
</div>
<!--Owner place of Residence-->
<div class="form-group">
<label class="col-sm-4 control-label">Date of Purchase</label>
<div class="col-sm-8">
<input type="text" name="date_of_purchase" id="datepicker" class="form-control" />
</div>
<?php echo form_error('date_of_purchase');?>
</div>
</div><!-- panel-body -->
<div class="panel-footer">
<button class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div><!-- panel-footer -->
</div><!-- panel-default -->
<?php form_close();?>
答案 0 :(得分:0)
我在我的视图代码中发现了一个错误或更确切的内容......特别是这部分
<!--IDno-->
<div class="form-group">
<label class="col-sm-4 control-label">Identification/Passport No</label>
<div class="col-sm-8">
<select class="form-control mb15" placeholder="Identification/Passport No">
<?php foreach($idnos as $row){
echo '<option value="'.$row['idno'].'">'.$row['username'].'</option>';
}
?>
</select>
</div>
<?php echo form_error('idno');?>
</div>
这就是它的样子,但在这一行上,
<select class="form-control mb15" placeholder="Identification/Passport No">
这应该是什么样子
<select class="form-control mb15" name="idno" placeholder="Identification/Passport No">
错过了 name =“idno” ... 它很容易在数据库中插入...感谢您的帮助@Lajos Arjad和@Daniel