Home > PHP Framework > ThinkPHP > body text

How to query if there is data in thinkphp

藏色散人
Release: 2022-12-09 09:17:22
Original
1453 people have browsed it

thinkphp查询是否有数据的方法:1、打开相应的tp文件;2、通过“M("gkwh_dictdata");”实例化对象;3、使用“if($list_dictdata !== null) {$obj->code = -1;...}”语句判断数据是否存在即可。

How to query if there is data in thinkphp

本教程操作环境:Windows7系统、ThinkPHP5版、Dell G3电脑。

thinkphp怎么查询是否有数据?

thinkphp mode find()方法查询记录是否存在的方法

代码如下:

       //字符过滤
       $mode = M("gkwh_dictdata"); // 实例化对象
       $where = "data_value = '".trim($_POST["famiMembFana"])."' or data_value = '".trim($_POST["famiMembLana"])."'";
       $list_dictdata = $mode->where($where)->find(); 
 
       //如果记录存在    
       if($list_dictdata !== null) {
          $obj->code = -1;
         
          $msg = "注册信息有非法字符";
       $obj->msg = $msg;
       $obj->data  = $list_dictdata;      
       $obj->count = 0;
       echo json_encode($obj);
       die;
       }
Copy after login

推荐学习:《thinkPHP视频教程

The above is the detailed content of How to query if there is data in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template