[eluser]Faisal Alghamdi[/eluser]
Hi everybody,
I am developing a control panel for my website.
And, I have been trying to update multiple records in my db.
But, the point is that I could not make a successful attempt to update more than one.
I have some records that should be either published or rejected.. I used drop-down
I was able to have forms in each row but in this case I have to update every record individually which is time-consuming.
Help me in debugging it and figure out what caused the problem, please
controller
Code:
function records_approval() {
$this->admin_is_logged_in();
$data = array (
'mod_name' => $this->admin_model->mod_name(),
'JOB_NAME' => array('name'=>'JOB_NAME', 'size'=>30),
'CITY' => array('name'=>'CITY', 'size'=>30),
'approval' => array('name'=>'approval', 'size'=>30),
'idRECORD' => array('name'=>'idRECORD', 'size'=>30),
// utk
'numbers' => $this->admin_model->records_approval(),
'title' => 'records approvals',
'records_approval' => 'admin/records_approval_view',
);
$this->load->view('cp_view', $data);
}
model
Code:
function upd() {
$data = array(
'JOB_NAME'=>array($this->input->post('JOB_NAME')),
'CITY'=>array($this->input->post('CITY')),
'approval'=>array($this->input->post('approval')),
'idRECORD'=>array($this->input->post('idRECORD')),);
$this->db->where('idRECORD',array($this->input->post('idRECORD')));
if($this->db->update('main_records',$data)) {
echo "Done";
echo anchor("cp/records_approval"," Back ");
}
}
view
Code:
<table id="mytable" cellspacing="0" border="0">
<?php
foreach($numbers as $row ){
echo form_open('cp/edit','name="login"');
echo "<td >$row->EMAIL</td>";
echo "<td>".form_input($JOB_NAME,$row->JOB_NAME)."</td>";
$total = $row->SALARY+=$row->BOUNS;
echo "<td >".$total." SR"."</td>";
echo "<td>". $row->CATE_NAME ."</td>";
echo "<td>".form_input($CITY,$row->CITY)."</td>";
echo "<td>";
echo "<select id='approval' name='".$approval."'>";
echo "<option value='0'> suspend </option>";
echo "<option value='1'>publish</option>";
echo "<option value='2'>reject</option>";
echo "</select>".br();
echo form_hidden($idRECORD,$row->idRECORD);
echo "</td>";
echo "</tr>";
}
echo form_submit('change','save changes');
echo form_close();
?>
</table>
the form sends to controller:: edit
Code:
function edit() {
$this->admin_is_logged_in();
if($this->input->post('change')){
$this->admin_model->upd();
}
}