Home  >  Article  >  Backend Development  >  像这么的查询还有别的什么方法可写吗

像这么的查询还有别的什么方法可写吗

WBOY
WBOYOriginal
2016-06-13 13:07:03962browse

像这样的查询还有别的什么方法可写吗?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->public function find()
    {
        $sql = "SELECT * FROM qsj_user_profile
        RIGHT JOIN qsj_user ON qsj_user.uid = qsj_user_profile.uid";
        if(!empty($_GET['email']))
        {
            $sql.="AND qsj_user.email=".$_GET['email'];
        }
        if(!empty($_GET['nickname']))
        {
            $sql.="AND qsj_user_profile.nickname = ".$_GET['nickname'];
        }
        if(!empty($_GET['province']))
        {
            $sql.="AND qsj_user_profile.province =".$_GET['province'];
        }
        if(!empty($_GET['city']))
        {
            $sql.="AND qsj_user_profile.city =".$_GET['city'];
        }
        if(!empty($_GET['dist']))
        {
            $sql.="AND qsj_user_profile.dist = ".$_GET['dist'];
        }
        if(!empty($_GET['style']))
        {
            $sql.="AND qsj_user_profile.style =".$_GET['style'];
        }
        $query = $this->db->query($sql);
        return $query->result_array();
        
    }


------解决方案--------------------
AND前最好留一个空格。
------解决方案--------------------
反正也不多。就这么写吧。
可以适当的改变一下数据放到数组里。
用foreach遍历。
当然也会遇到不同的问题。

这个就需要摸索和积累了
------解决方案--------------------
这种写法基本上就这样了
------解决方案--------------------
就这样写吧。没问题的。以后去找好的方法。
Statement:
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