求助 版主:官方研发技术组
表单查询,证书或编号其中任一项可查询
类型:迅睿CMS 更新时间:2023-06-01 09:18:59 不能为空


https://www.xunruicms.com/doc/1055.html
这个是搜索 证书+编号的代码

<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时可以修改本文件,不影响升级覆盖
 */

class Zhengshu extends \Phpcmf\Home\Form
{

    public function index() {
        $this->_Home_List();
    }

    public function show() {
        $this->_Home_Show();
    }

    public function post() {
        $this->_Home_Post();
    }

    public function search() {

        // 接收url传递的值
        $title = dr_safe_replace(\Phpcmf\Service::L('input')->get('title'));
        $zsbh = dr_safe_replace(\Phpcmf\Service::L('input')->get('zsbh'));
        if (!$title) {
            $this->_msg(0, '证书名称不能为空');
        }
        if (!$zsbh) {
            $this->_msg(0, '证书编号不能为空');
        }

        // 查询
        $row = \Phpcmf\Service::M()->table($this->init['table'])->where('title', $title)->where('zsbh', $zsbh)->getRow();
        if (!$row) {
            $this->_msg(0, '没有查询到');
        }

        // 查询到了调转到表单详情页面
        $url = SITE_URL.'index.php?s=form&c='.$this->form['table'].'&m=show&id='.$row['id'];

        dr_redirect($url);
    }

}


如何改成输入证书或编号两项的其中一项就可以查询? 谢谢.
  

回帖
  • 官方研发技术-陈老师
    #1楼    官方研发技术-陈老师
    2023-05-31 17:04:08
    Chrome 0
    这个很好实现啊,代码都大部分代码都写好了,只需要你分期代码,你看代码上面写的是两个字段条件都匹配,它是and的关系,你只需要改成or的关系,就是或者的关系,把程序代码改成或者两个,二选一都可以,这种条件意思就是让你重新组合一个条件。
    if (!$title and !$zsbh) {
                $this->_msg(0, '证书编号和title不能同时为空');
            }
    
            // 查询
            $row = \Phpcmf\Service::M()->table($this->init['table'])->where('title="'. $title.'" or zsbh="'. $zsbh.'"')->getRow();
            if (!$row) {
                $this->_msg(0, '没有查询到');
            }
    以上代码仅供参考,可能会有错误,具体你要实测一下。
  • 活在当下
    #2楼    活在当下
    2023-05-31 17:06:10
    Chrome 0
    谢谢,陈老师.
  • 活在当下
    #3楼    活在当下
    2023-05-31 23:47:21
    Chrome 0

    dd

    这个地方的证书怎么去掉呢?
  • 张大山
    #4楼    张大山
    2023-06-01 07:14:40
    Chrome 0
    模板里面找标签,找的标签就把它删掉就可以了,简单了。
  • 活在当下
    #5楼    活在当下
    2023-06-01 09:18:59
    Chrome 0
    非常感谢,可以了.