0
<?php //controller
function notif()
{
    $condition = $this->business_model->get_condition();
    $this->data['query'] = $this->business_model->data_pagination_admin($condition);
        $this->load->view('student_result',$this->data);
}
?>

<?php //model
function get_condition()
{

  $this->db->select('condition');
  $this->db->from('staff');
  $query = $this->db->get(); 
  return $query->result_array();
}

function data_pagination_admin($condition)//notif function
{
    //...........
    $this->db->where('flag','n');
    //$user_id = $this->session->userdata('condition');
    $this->db->where($condition,$user);//notice parameter condition
    $this->db->order_by('next_date','asc');
    $query = $this->db->get('student',10,0);
    return $query->result_array();
}

 /*im getting error :"Unknown column '0' in 'where clause'

SELECT * FROM (`student`) JOIN `status_table` ON `student`.`stud_id` = 
   `status_table`.`stud_id` WHERE `status_table`.`next_date` > '2013-06-09 23:59:59'
 AND     `flag` = 'n' AND **`0` = Array ORDER** BY `next_date` asc LIMIT 10"*/


?>

1.im 从模型获取值到控制器并将其传递给控制器​​到另一个函数,但出现错误。

2.controller->get_condition->controller->data_pagination_admin()

3.get 条件函数将只返回一个字符串,仅此而已

4

2 回答 2

0

get_condition当前返回一个数组;试试下面的代码:

function get_condition()
{
$user = $this->session->userdata('user_id');
$this->db->select('condition');
$this->db->from('staff');
$this->db->where('user_id',$user );
$query = $this->db->get(); 
$result = $query->row_array();
return $result['condition'];
}

编辑:看起来你在 where 子句中的 $user var 也是一个数组。

于 2013-06-10T10:19:15.290 回答
0

您可以使用var_dump()来查看某些变量和结果的值是什么。您不应该使用$query->row()它,因为它只会返回 1 行。我建议你应该像这样迭代数组:

foreach($query->result() as $result)
    {
    $this->data['query'].=$result
    }
于 2013-06-10T10:38:41.787 回答