首页 > 解决方案 > 在同一函数中获取 num_rows 和 result() 数据,并在 codeigniter 中传递给控制器​​数据

问题描述

我试图向用户展示数据库中的内容并询问他是否仍想插入他输入的信息,但我正在努力将他们的数据发送到我的控制器。

这是我到目前为止所拥有的:

控制器

$result = $this->call_model->checkCallExists($callInfo);

if($result == true) { 
                

模型

function checkCallExists($callInfo)
{
    //pre($callInfo);      
    //die;

    $this->db->select("*");
    $this->db->from("tbl_calls");
    $this->db->where("type_of_equipment", $callInfo['type_of_equipment']);   
    $this->db->where("fk_location_id", $callInfo['fk_location_id ']);
    $this->db->where("fk_status_id", $callInfo['fk_status_id ']);
    $query = $this->db->get();

    if ($query->num_rows() > 0){
            $retun_array['data']= $query->result_array();
            return false;
        }
        else{
            return true;
    }
}

这就是我在模型中进行转储时得到的

在此处输入图像描述

我想以表格形式显示它,并带有一个取消或插入数据库的按钮,但我没有将数据发送到我的控制器。

先感谢您。

标签: phpsqlcodeigniter

解决方案


您正在返回“真”或“假”。而不是“真”返回结果数组

模型:

  if ($query->num_rows() > 0){  
        $return_array['data']= $query->result_array();
        return $return_array;
  }
  else{
        // no records found
        return false;
  }

或更短:

return ($query->num_rows())? $query->result_array():false;

控制器:

$result = $this->call_model->checkCallExists($callInfo);

if($result){ 
    echo'<pre>';print_r($result);die;  //comment this line to continue
    // send data to view
    $this->load->view('your_view', $result)
}

推荐阅读