【发布时间】:2011-11-30 16:28:44
【问题描述】:
我们能否在 MODEL [CODIGNITER] 中检查 mysql 查询是否返回 true 或 false 并根据请求执行 if else 语句
模型中的一个 sql 语句执行是否 sql 语句给出 num_rows>0 如果它给出了我需要执行一个函数 else 继续其他行
【问题讨论】:
-
您能详细说明一下吗?问题不够清楚,抱歉。
标签: php mysql codeigniter
我们能否在 MODEL [CODIGNITER] 中检查 mysql 查询是否返回 true 或 false 并根据请求执行 if else 语句
模型中的一个 sql 语句执行是否 sql 语句给出 num_rows>0 如果它给出了我需要执行一个函数 else 继续其他行
【问题讨论】:
标签: php mysql codeigniter
当然,这是一个人为的例子。
class Blogmodel extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function blog_exists( $id )
{
$query = $this->db->query('SELECT * FROM BLOG WHERE BLOG.ID = '. $id);
if( $query->num_rows() > 0 )
return true;
else
return false;
}
}
【讨论】:
代码的任何部分都没有进入控制器。您需要在模型中创建另一个函数,根据控制器函数的真假调用该函数。例如:- 在模型中:-
<?php
function xyz($flag){
if(----)return true;
else return false;
function abc($flag){----};
function ghi($flag){----};
?>
在控制器中:-
function call($var){
if(xyz($var)==TRUE) abc($var);
else ghi($var);
?>
【讨论】: