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

时间:2015-06-08 07:08:45

标签: php jquery mysql codeigniter

请帮帮我。我无法正确使用我的dataTable。我想做的是

select from table and use the,其中function。但我不能正确地做到这一点。

这是我的控制器代码

 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();
    }

这是我所谓的查询:

  

从tblreport中选择*,其中empnumber =(我的文本框中的数字。)

在那里,我从文本框中获取一个值到我的视图。但它不起作用。我知道这是错的。你能帮我解决一下我的问题吗?谢谢。

<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;?>"/>

这是我对导游的看法。谢谢。

3 个答案:

答案 0 :(得分:2)

简单就可以使用

控制器

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

中的

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
}

视图

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

}?>

答案 1 :(得分:0)

试试这个:

使其更简单。

模特:

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')
}

在控制器中:

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.
}

答案 2 :(得分:0)

控制器

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

中的

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 }

视图

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