Welcome Guest, Not a member yet? Register   Sign In
Delete multiple record using checkbox...
#1

[eluser]bianchi[/eluser]
Hello friends,

I wanna delete multiple records using checkbox...

I always get

Call to a member function delete() on a non-object in C:\Program Files\xampp\htdocs\fids_2\module\application\controllers\checkbox.php on line 27
==============

Any helps / suggestions will be appreciated..

Thx..
==================
The controller :
<?
class Checkbox extends Controller{

function Checkbox(){
parent::Controller();
$this->load->helper('url');
$this->load->database();
}
function index(){
//$this->load->library('table');
//load pagination class
//$this->load->library('pagination');
//$this->load->helper('html');
$this->load->model('checkboxModel');

//load model and ambil hasilnya

$data['query'] = $this->checkboxModel->checkbox_getall();
$this->load->view('checkbox_view',$data);

}

function delete(){
$dat=$this->input->post('airline');
for($i=0; $i<sizeof($dat);$i++)
{
$this->checkboxModel->delete($dat[$i]);
}

//$this->load->view('checkbox_view3',$data);
}
}
?&gt;

The model :
&lt;?php
class checkboxModel extends Model
{


function checkbox_getall()
{
$this->load->database();
$this->db->order_by('name','asc');
$this->db->limit(10);
$query = $this->db->get('ins_code_airlines');
return $query->result();
}

function delete($code2)
{
//$this->db->where('code2', $code2);
//$this->db->delete('ins_code_airlines');
$this->db->query("DELETE FROM 'ins_code_airlines' WHERE `code2` = '$code2' ");

}



}
?&gt;

the view :
&lt;html&gt;
&lt;head&gt;
[removed]
&lt;!--

&lt;!-- Begin
function CheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}

function UnCheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
// End --&gt;
[removed]
&lt;/head&gt;
&lt;body&gt;

<br>
&lt;form name="airline_form" action="checkbox/delete" method="post"&gt;
&lt;input type="button" name="Check_All" value="Check All"&gt;
&lt;input type="button" name="Un_CheckAll" value="Uncheck All"&gt;
&lt;input type="submit" value="DELETE" class="button"/&gt;
<br>

&lt;? //foreach($query as $row){ echo "<option value='$row->code2'>$row->name</option>";}
foreach($query as $row){ echo "&lt;input type='checkbox' name='airline1' value='$row-&gt;code2'>$row->name<br>";}?&gt;
&lt;input type="submit" value="DELETE" class="button"/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]eoinmcg[/eluser]
please format code, it makes it much easier for people to read and help...

anyways, you should load the model in the controller constructor:
Code:
function Checkbox(){
      parent::Controller();
      $this->load->helper('url');
      $this->load->database();
      $this->load->model('checkboxModel');
    }
#3

[eluser]bianchi[/eluser]
thanks for the advice...it works...




Theme © iAndrew 2016 - Forum software by © MyBB