codeigniter Insert_batch не работает

Я пытаюсь вставить несколько строк в таблицу базы данных, используя codeigniter insert_batch. На основании сообщения об ошибке кажется, что столбцы таблицы не установлены. только количество массивов:

отчет об ошибках браузера

Мой взгляд:

<table class="table">
<center><h3> Activity Name: <?php echo $activity_name; ?></h3><h4> Date: <?php echo $activity_date; ?></h4></center>
<tr>
<td>Member Name and Course</td>
<td>Attendance</td>
<td>fee</td>
</tr>
<?php
$count = 1;
$member_count = 1;
foreach ($students as $row) {
$uID = $row['user_ID'];
$cID = $row['council_ID'];
$aID = $row['activity_ID'];
$name = $row['user_LastName'].", ".$row['user_FirstName'];
$course = $row['user_Course'];
$year = $row['user_Year'];
?>
<tr>
<td>
<h4> <?php echo $member_count.". ".$name; ?></h4>
<h5> &nbsp;&nbsp;&nbsp;&nbsp; <?php echo $course." - ".$year; ?></h5>
</td>
<?php echo form_open('Isidran/InsertAttendance'); ?>
<input type="hidden" id="uID<?php echo $count; ?>" name="uID[]" value="<?php echo $uID;?>">
<input type="hidden" id="cID<?php echo $count; ?>" name="cID[]" value="<?php echo $cID;?>">
<input type="hidden" id="aID<?php echo $count; ?>" name="aID[]" value="<?php echo $aID;?>">
<input type="hidden" id="aname<?php echo $count;?>" name="aname[]" value="<?php echo $activity_name; ?>">
<td><select id="attendance<?php echo $count; ?>" name="attendance[]" class="form-control">
<option value="Absent">  Absent </option>
<option value="Present"> Present </option>
</select>
</td>
<input type="hidden" id="name<?php echo $count;?>" name="name[]" value="<?php echo $name;?>">
<input type="hidden" id="fines<?php echo $count; ?>" name="fines[]" value="<?php echo $activity_fee; ?>">
<td><div id="fee<?php echo $count; ?>"><?php echo $activity_fee; ?></div> </td>
</tr><br />
<script type="text/javascript">
$(function() {
$('#attendance<?php echo $count; ?>').change(function(){
var activity_fee = '<?php echo $activity_fee; ?>'
if($('#attendance<?php echo $count; ?>').val() == 'Absent') {
$('#fee<?php echo $count; ?>').show();
$('#fee<?php echo $count; ?>').text('<?php echo $activity_fee; ?>');
} else {
$('#fee<?php echo $count; ?>').show();
$('#fee<?php echo $count; ?>').text('0');
$('#fines<?php echo $count; ?>').val('0');
}
});
});
</script>
<?php $count++; $member_count++; } ?>
<tr>
<td colspan="3"><button type="submit" id="btn_submit" class="btn btn-info pull-right">Submit</button></td>
</tr>
<?php echo form_close(); ?>
</table>

Мой контроллер:

public function InsertAttendance()
{
$attendance_data = array(
'attendance_userID' => $this->input->post('uID[]'),
'attendance_councilID' => $this->input->post('cID[]'),
'attendance_activityID' => $this->input->post('aID[]'),
'attendance_activity' => $this->input->post('aname[]'),
'attendance_status' => $this->input->post('attendance[]'),
'attendance_sname' => $this->input->post('name[]'),
'attendance_fines' => $this->input->post('fines[]'));
$data['result'] = $this->Site_model->insertAttendance($attendance_data);
if($data['result'] == true)
{
$this->session->set_flashdata('feedback', '<div class="alert alert-success alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>Added Successfully</strong>
</div>');
redirect('Isidran/Home');
}
}

и модель:

public function insertAttendance($data)
{
$this->db->insert_batch('tbl_council_activity_attendance', $data);
if($this->db->affected_rows() > 0)
{
return true;
}
}

0

Решение

Пытаться

public function insertAttendance($data)
{
$attendance=array(
'column1' => $data['index1'],
'column2' => $data['index2'],
'column3' => $data['index3'],
.
.
);
$this->db->insert('tbl_council_activity_attendance', $attendance);
if($this->db->affected_rows() > 0)
{
return true;
}
}
0

Другие решения

Если вы хотите вставить пакет, чем ваш массив данных будет

$array_name=array(
array(
'col1'=>'data',
'col2'=>'data',
'col3'=>'data'
),
array(
'col1'=>'data',
'col2'=>'data',
'col3'=>'data'
)
);
0

По вопросам рекламы [email protected]