从模型到控制器并返回到模型的数据

时间:2013-06-10 09:56:12

标签: php mysql codeigniter

<?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.从模型到控制器的最小值并将其传递给控制器​​到另一个控制器 功能,但得到错误。

2.controller-&GT; get_condition-&GT;控制器 - &GT; data_pagination_admin()

3. get条件函数将只返回一个全部

的字符串

2 个答案:

答案 0 :(得分: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'];
}

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

答案 1 :(得分:0)

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

foreach($query->result() as $result)
    {
    $this->data['query'].=$result
    }