我需要从数据库中检索显示值的td标记中携带的值,然后将它们插入到不同的数据库中。我从模型中检索了两个值seateat和seatLabel,并在带有seatNumber值的checkboxex中显示它们。 / p>
我的用于获取seatValue的模型
public function getSeats(){
$query = $this->db->get('seat');
if($query->num_rows() > 0){
return $query->result();
}
}
我用于显示seatNumber和seatLabel的视图
<tbody>
<?php if(count ($seats)):?>
<?php foreach ($seats as $seat):?>
<tr>
<td><input type="checkbox" name="seat_id[]" value=<?php echo $seat->seatNumber;?>></td>
<td id="seatLabel" name="seat_label"><?php echo $seat->seatLabel;?></td>
</tr>
<?php endforeach;?>
<?php else:?>
<td>No Records Founds!</td>
<?php endif;?>
</tbody>
我的控制器
public function message(){
if ($this->input->post('submit') == 'Set Schedule') {
$this->form_validation->set_rules('busNumber','Bus Number', 'required');
$this->form_validation->set_rules('seat_id[]','Seats', 'required');
$this->form_validation->set_rules('bookingDate','Date of Journey', 'required');
$this->form_validation->set_rules('reportingTime','Reporting Time', 'required');
$this->form_validation->set_rules('departureTime','Departure Time', 'required');
if($this->form_validation->run()){
$seat_ids = $this->input->post("seat_id[]");
$seat_label = $this->input->post("seat_label");
$busNumber = $this->input->post("busNumber");
$bookingDate = $this->input->post("bookingDate");
$reportingTime = $this->input->post("reportingTime");
$departureTime = $this->input->post("departureTime");
$this->load->model('Queries');
$insert = $this->Queries->saveMessage($seat_ids, $seat_label, $busNumber, $bookingDate, $reportingTime, $departureTime);
if($insert) {
echo "Success";
}
else {
echo "error";
}
} else {
echo validation_errors();
}
}
我将日期插入新数据库的模型
public function saveMessage($seat_ids, $seat_label, $busNumber, $bookingDate, $reportingTime, $departureTime){
foreach($seat_ids as $seat_id)
{
$record = array(
'seatNumber' => $seat_id,
'seatLabel' => $seat_label
'bookingDate' => $bookingDate,
'reportingTime' => $reportingTime,
'departureTime' => $departureTime,
'busNumber' => $busNumber,
'seatUse' => 'Enabled',
'seatStatus' => 'Available',);
$this->db->insert('schedule', $record);
}
return true;
}
数据库中出现问题,没有固定价值
错误
答案 0 :(得分:1)
有这样的方法。如果您更改
SignInManager<User>
UserManager<User>
到
<td id="seatLabel" name="seat_label"><?php echo $seat->seatLabel;?></td>
但是,如果您不想显示文本框,则还要创建隐藏字段。
<td><input type="text" name="seat_label" value="<?php echo $seat->seatLabel;?>"></td>