Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter: this->datatables->select(sample)->from(sample)->where()

Please help me. i can not use my dataTable properly. what I want to do is

select from table and use thewherefunction. but i cant do it properly.

here is my controller code

 public function reporttable ()
    {

        $zz = array('empnumber' => $this->input->post('empnumber'));
        //$this->db->order_by("surname", "asc");
         $this->datatables->select('date_auto,particulars,earned_VL,aul_VL,balance_VL,aulx_VL,earned_SL,aul_SL,balance_SL,aulx_SL,date_leave,action_taken')
        ->from('tblreport')->where($zz);

        echo $this->datatables->generate();
    }

this is my supposed query:

select * from tblreport where empnumber = (the empnumber in my textbox.)

there, i get a value from a textbox to my view. but it didn't work. i know that is wrong. can you please help me with my problem? thank you.

<p align="center"> <?php echo $this->table->generate();?></p></div>
<?php foreach ($tblemployee as $row){?> 
<input type="text" name="empnumber" readonly="readonly"  value="<?php echo $row->empnumber;?>"/>
<input type="hidden" name="empnumber" value="<?php echo $row->empnumber;?>"/>

here is my view for guide. thank you.

like image 239
JB Omega Avatar asked Sep 23 '26 22:09

JB Omega


1 Answers

as Simple you can use

In Controller

$data['tblemployee'] = $this->model_name->reporttable($id)//assign your data base value to variable 
$this->load->view('your view name',$data )

in Model

public function reporttable($id)
    {
    $query = $this->db->query("select * from tblreport where empnumber = '$id'");
    $result = $query->result_array();
    return $result; // this will return your data as array
}

In view

<?php 
foreach ($tblemployee as $row)
{
echo $row['id];

}?>
like image 111
Abdulla Nilam Avatar answered Sep 25 '26 12:09

Abdulla Nilam