php - 在同一函数中获取 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;
}
}
这就是我在模型中进行转储时得到的
我想以表格形式显示它,并带有一个取消或插入数据库的按钮,但我没有将数据发送到我的控制器。
先感谢您。
解决方案
您正在返回“真”或“假”。而不是“真”返回结果数组
模型:
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)
}
推荐阅读
- javascript - 在javascript中获取内部函数名称?
- javascript - 如何从 defaultProps 迁移到默认参数
- python - 如何在 JupyterLab 或 Jupyter Notebook 中找回代码块
- python-3.x - 是否可以将标量值与 Pandas 系列一起传递给 Pandas UDF 函数
- svn - Svn 代码签入到其他分支而不提交到当前分支
- python - 如何访问 Django Rest API 中添加的最后一个元素?
- r - stats::model.frame 中的错误...:在 geom_smooth 中指定权重时找不到对象
- python - 在 Python 中读取 FTP 文件内容并同时用于 Pandas 和直接
- elasticsearch - 在 ElasticSearch v7.3 的字段中找到关键字的偏移量
- xml - 如何替换文本中的一些xml标签