• PHP多条件查询处理


    PHP多条件查询处理

    在SQL里面写这种查询的地方很多,要让查询写得富化。
    //方法一
    //获取字典类型

    $sztm=trim($_REQUEST['ztm']);
    $stmpy=trim($_REQUEST['tmpy']);
    $sssh=trim($_REQUEST['ssh']);
    $scbm=trim($_REQUEST['cbm']);

    $sql = 'select * from ts_gcb ';

    if ( $sztm != '' ){
     $sql  .= ' where ztm like "%'.$sztm.'%" ';
    }

    if ( $stmpy != '' ){
     $sql .= ( preg_match('/where/' , $sql ) ? ' and ': ' where ' ) . ' tmpy like "%'.$stmpy.'%" ';
    }

    if ( $sssh != '' ){
     $sql .= ( preg_match('/where/' , $sql ) ? ' and ': ' where ' ) . ' ssh like "%'.$sssh.'%" ';
    }

    if ( $scbm!= '' ){
     $sql .= ( preg_match('/where/' , $sql ) ? ' and ': ' where ' ) . ' cbm like "%'.$scbm.'%" ';
    }


    echo $sql;

    $conn = mysql_connect($dbhost, $dbuser, $dbpwd);
    mysql_select_db($dbname);
    $rst = mysql_query($sql, $conn);


    ///方法二


    if(empty($isbn))
    {
       $where[]="`isbn` like '%$isbn%'";
    }

    implode(' and ',$where);

  • 相关阅读:
    iOS中的HTTPS
    HTTPS抓包之Charles
    组件化开发的一些思考
    Xcode 调试技巧
    iOS崩溃日志分析
    iOS依赖库管理工具之Carthage
    13.类的关系总结
    12.组合(Composition)
    11.聚合(Aggregation)
    10.关联(Association)
  • 原文地址:https://www.cnblogs.com/fengju/p/6174014.html
Copyright © 2020-2023  润新知