JB Omega
JB Omega

Reputation: 83

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.

Upvotes: 3

Views: 2878

Answers (3)

pravi
pravi

Reputation: 1

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]; }?>

Upvotes: 0

aiai
aiai

Reputation: 1139

Try this :

To make it more simplier.

In model :

public function reporttable ($id){

  $this->db->select('*');
  $this->db->from('tblreport');
  $this->db->where('empnumber', $id);

  $query =  $this->db->get();
  return $query->return_array(); // use this if so want to return many query if not you can also use first_row('array')
}

In controller :

public function function_name (){
  $data['variable_name'] =  $this->model_name->reporttable($id); // change the model_name by your own model where your function reporttable is located and use the variable_name for your view,

  $this->load->view('view_name' , $data); // load the view page you want to display.
}

Upvotes: 0

Abdulla Nilam
Abdulla Nilam

Reputation: 38670

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];

}?>

Upvotes: 2

Related Questions