Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial thinkphp筛选问题

thinkphp筛选问题

Jun 23, 2016 pm 01:49 PM
thinkphp filter



怎么根据这2个字段进行双晒选呢~~


回复讨论(解决方案)

做个沙发 静等高手哥哥的回答~~

$Model->where($condition)->select();
$condition和平常sql一样写就行了,可以写多个条件and连接

TP有自己封装好的函数进行操作,也可以使用SQL语句进行操作,看你需求,如果是很复杂的话自己写SQL运行,如果不是的话TP封装好的那些函数就完全足够了。不过像LZ这种只是两个条件进行查询的话采用楼上的方法完全足够了。

M('tablename')->where("Position = 'xxx' and Recruitment = 'xxx'")->select();

$Model->where($condition)->select();
$condition和平常sql一样写就行了,可以写多个条件and连接




抱歉  完全不会写~~能否写的全一点呢????  新手~~

TP有自己封装好的函数进行操作,也可以使用SQL语句进行操作,看你需求,如果是很复杂的话自己写SQL运行,如果不是的话TP封装好的那些函数就完全足够了。不过像LZ这种只是两个条件进行查询的话采用楼上的方法完全足够了。



抱歉  完全不会写~~能否写的全一点呢????  新手~~

TP有自己封装好的函数进行操作,也可以使用SQL语句进行操作,看你需求,如果是很复杂的话自己写SQL运行,如果不是的话TP封装好的那些函数就完全足够了。不过像LZ这种只是两个条件进行查询的话采用楼上的方法完全足够了。



抱歉  完全不会写~~能否写的全一点呢????  新手~~


$Model->where($condition)->select();
$condition和平常sql一样写就行了,可以写多个条件and连接




抱歉  完全不会写~~能否写的全一点呢????  新手~~

1

$Model=M("tablename");//这里把tablename换成你的表名$list=$Model->where("Position = 'xxx' and Recruitment = 'xxx'")->select(); //这里像平常写sql一样,把xxx内容换成你两个字段的条件要求$this->assign("list",$list);//最后把查询的数组结果,传入模板中,在模板中循环调用就行了

Copy after login
Copy after login
Copy after login
Copy after login



$Model->where($condition)->select();
$condition和平常sql一样写就行了,可以写多个条件and连接




抱歉 完全不会写~~能否写的全一点呢???? 新手~~


1

$Model=M("tablename");//这里把tablename换成你的表名$list=$Model->where("Position = 'xxx' and Recruitment = 'xxx'")->select(); //这里像平常写sql一样,把xxx内容换成你两个字段的条件要求$this->assign("list",$list);//最后把查询的数组结果,传入模板中,在模板中循环调用就行了

Copy after login
Copy after login
Copy after login
Copy after login



我就是没有搞懂 那个XXX是怎么传值的
第一个筛选还是其他的?




$Model->where($condition)->select();
$condition和平常sql一样写就行了,可以写多个条件and连接




抱歉 完全不会写~~能否写的全一点呢???? 新手~~


1

$Model=M("tablename");//这里把tablename换成你的表名$list=$Model->where("Position = 'xxx' and Recruitment = 'xxx'")->select(); //这里像平常写sql一样,把xxx内容换成你两个字段的条件要求$this->assign("list",$list);//最后把查询的数组结果,传入模板中,在模板中循环调用就行了

Copy after login
Copy after login
Copy after login
Copy after login



我就是没有搞懂 那个XXX是怎么传值的
第一个筛选还是其他的?




public function shaixuan(){
$data=M('zhaopin');
$aid=$_GET['id'];
$lists = $Data->where("Position = '$aid' and Recruitment = '$aid'")->select();
$this->assign('lists',$lists);
$this->display('index');
}




$Model->where($condition)->select();
$condition和平常sql一样写就行了,可以写多个条件and连接




抱歉 完全不会写~~能否写的全一点呢???? 新手~~


1

$Model=M("tablename");//这里把tablename换成你的表名$list=$Model->where("Position = 'xxx' and Recruitment = 'xxx'")->select(); //这里像平常写sql一样,把xxx内容换成你两个字段的条件要求$this->assign("list",$list);//最后把查询的数组结果,传入模板中,在模板中循环调用就行了

Copy after login
Copy after login
Copy after login
Copy after login



我就是没有搞懂 那个XXX是怎么传值的
第一个筛选还是其他的?


1

public function  shaixuan(){$data=M('zhaopin');$aid=$_GET['id'];$lists = $Data->where("Position = '$aid' and Recruitment = '$aid'")->select();$this->assign('lists',$lists);$this->display('index');}<volist name="lists" id="vo">    <a href="/index.php/Zhaopin/shaixuan/id/{$vo[id]}">{$vo['Position']}</a>    </volist>

Copy after login

汗,这个xxx没有规定怎么传啊,这个是条件,条件就是你想通过它来限制得到你想要的结果,那我问你,你为什么需要这两个字段来并列筛选呢,为什么不是所有字段都筛选呢!同理,比如你想筛选Position是111的记录,那就是$Data->where("Position = '111'")->select();至于这个111如果是动态传过来的,就像你写的,先获取,再组装到sql

你看你的项目如果你是直接M或者是D函数啥的就直接将页面传递过来的数据(包含GET、POST等一些列传参),然后填充到where中,如果你是按照表建立的单独的model类那你需要在public的方法中增加参数传入,如下:

1

/**     * @todo get one news info     */    public function getOneNewsInfo($id){        $where = '`id` = \''.$id.'\'';        return $this->where($where)->select();    }

Copy after login
Copy after login

否则,就直接在页面调用:

1

$model = M('table'); $where = '`id` = \''.$id.'\'';        $model ->where($where)->select();

Copy after login
Copy after login

你看你的项目如果你是直接M或者是D函数啥的就直接将页面传递过来的数据(包含GET、POST等一些列传参),然后填充到where中,如果你是按照表建立的单独的model类那你需要在public的方法中增加参数传入,如下:

1

/**     * @todo get one news info     */    public function getOneNewsInfo($id){        $where = '`id` = \''.$id.'\'';        return $this->where($where)->select();    }

Copy after login
Copy after login

否则,就直接在页面调用:

1

$model = M('table'); $where = '`id` = \''.$id.'\'';        $model ->where($where)->select();

Copy after login
Copy after login






恩 的确是获取到ID了 问题是 下面的内容不变化啊

1

public function index(){            $Data = M('zhaopin'); // 实例化Data数据对象            import('ORG.Util.Page');// 导入分页类            $count= $Data->where($map)->count();// 查询满足要求的总记录数            $Page= new Page($count,20);// 实例化分页类 传入总记录数         $nowPage = isset($_GET['p'])?$_GET['p']:1;          $adi=$_GET['id'];           $list = $Data->where($map,"Position = '$aid' and Recruitment = '$aid'")->order('shijian desc,id asc')->page($nowPage.','.$Page->listRows)->select();         $show = $Page->show();// 分页显示输出          $this->assign('page',$show);// 赋值分页输出            $this->assign('list',$list);// 赋值数据集         $this->display(); // 输出模板    }--------------------------------------------------下面是筛选-------------------------------------------------------------------------------------------------<a href="#" >全部</a> <volist name="list" id="vo"> <a href="/index.php/Zhaopin/index/id/{$vo[id]}">{$vo['Position']}</a>   </volist> </dd></dl><dl class="sz_area" id="sbl_"><dt>区域:</dt><dd><a href="停车场.html">全深圳</a> <volist name="list" id="vo">   <a href="/index.php/Zhaopin/index/id/{$vo[id]}">{$vo['Recruitment']}</a>    </volist> </dd>-----------------------------------------------------下面是内容-------------------------------------------------------------------------------------<volist name="list" id="vo"><dl class="jobli"><dt>  <span class="jobname" style="width:35%;"><a href="/index.php/Zhaopin/show/id/{$vo[id]}">{$vo['Job']|mb_substr=0,8,'UTF-8'}</a></span>   <span style="width:30%;"><a href="/index.php/Zhaopin/show/id/{$vo[id]}">{$vo['company_name']}</a></span>    <span style="width:16%;">{$vo['Recruitment']}</span>    <span style="width:15%;">{$vo['shijian']}</span></dt><dd>   <span class="jobinfo">        <b>           招聘人数:{$vo['hiring']}人               公司性质:{$vo['Nature']}                规模:{$vo['company_scale']}人              经验:{$vo['Work_experience']}年                学历:{$vo['Degree_required']}             职位月薪:{$vo['salary']}元/月     </b>      <br />        岗位要求: {$vo['Job_requirements']|mb_substr=0,150,'UTF-8'} </span>   <a href="/index.php/Zhaopin/show/id/{$vo[id]}" class="getjob">查看职位</a></dd></dl></volist>

Copy after login

汗,这个xxx没有规定怎么传啊,这个是条件,条件就是你想通过它来限制得到你想要的结果,那我问你,你为什么需要这两个字段来并列筛选呢,为什么不是所有字段都筛选呢!同理,比如你想筛选Position是111的记录,那就是$Data->where("Position = '111'")->select();至于这个111如果是动态传过来的,就像你写的,先获取,再组装到sql



恩 的确是获取到ID了 问题是 下面的内容不变化啊

1

public function index(){            $Data = M('zhaopin'); // 实例化Data数据对象            import('ORG.Util.Page');// 导入分页类            $count= $Data->where($map)->count();// 查询满足要求的总记录数            $Page= new Page($count,20);// 实例化分页类 传入总记录数            $nowPage = isset($_GET['p'])?$_GET['p']:1;            $adi=$_GET['id'];            $list = $Data->where($map,"Position = '$aid' and Recruitment = '$aid'")->order('shijian desc,id asc')->page($nowPage.','.$Page->listRows)->select();            $show = $Page->show();// 分页显示输出            $this->assign('page',$show);// 赋值分页输出            $this->assign('list',$list);// 赋值数据集            $this->display(); // 输出模板    }--------------------------------------------------下面是筛选------------------------------------------------------------------------------------------------- <a href="#" >全部</a> <volist name="list" id="vo">    <a href="/index.php/Zhaopin/index/id/{$vo[id]}">{$vo['Position']}</a>   </volist> </dd></dl><dl class="sz_area" id="sbl_"><dt>区域:</dt><dd><a href="停车场.html">全深圳</a> <volist name="list" id="vo">    <a href="/index.php/Zhaopin/index/id/{$vo[id]}">{$vo['Recruitment']}</a>   </volist> </dd>  -----------------------------------------------------下面是内容-------------------------------------------------------------------------------------<volist name="list" id="vo"><dl class="jobli"><dt>    <span class="jobname" style="width:35%;"><a href="/index.php/Zhaopin/show/id/{$vo[id]}">{$vo['Job']|mb_substr=0,8,'UTF-8'}</a></span>    <span style="width:30%;"><a href="/index.php/Zhaopin/show/id/{$vo[id]}">{$vo['company_name']}</a></span>    <span style="width:16%;">{$vo['Recruitment']}</span>    <span style="width:15%;">{$vo['shijian']}</span></dt><dd>    <span class="jobinfo">        <b>            招聘人数:{$vo['hiring']}人                公司性质:{$vo['Nature']}                规模:{$vo['company_scale']}人                经验:{$vo['Work_experience']}年                学历:{$vo['Degree_required']}                职位月薪:{$vo['salary']}元/月        </b>        <br />        岗位要求: {$vo['Job_requirements']|mb_substr=0,150,'UTF-8'}    </span>    <a href="/index.php/Zhaopin/show/id/{$vo[id]}" class="getjob">查看职位</a></dd></dl></volist>

Copy after login
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to filter more than 3 keywords at the same time in excel How to filter more than 3 keywords at the same time in excel Mar 21, 2024 pm 03:16 PM

Excel is often used to process data in daily office work, and it is often necessary to use the &quot;filter&quot; function. When we choose to perform &quot;filtering&quot; in Excel, we can only filter up to two conditions for the same column. So, do you know how to filter more than 3 keywords at the same time in Excel? Next, let me demonstrate it to you. The first method is to gradually add the conditions to the filter. If you want to filter out three qualifying details at the same time, you first need to filter out one of them step by step. At the beginning, you can first filter out employees with the surname &quot;Wang&quot; based on the conditions. Then click [OK], and then check [Add current selection to filter] in the filter results. The steps are as follows. Similarly, perform filtering separately again

What should I do if there is data in the Excel table but the blanks are filtered? What should I do if there is data in the Excel table but the blanks are filtered? Mar 13, 2024 pm 06:38 PM

Excel is a frequently used office software. Many users record various data in the table, but the table clearly contains data and is blank when filtering. Regarding this problem, many users don’t know how to solve it. It doesn’t matter. , the content of this software tutorial is to provide answers to the majority of users. Users in need are welcome to check out the solutions. What should I do if there is data in the Excel table but the blanks are filtered? The first reason is that the table contains blank rows. We want to filter all people with the surname "Li", but we can see that the correct results are not filtered out because the table contains blank rows. How to deal with this situation? Solution: Step 1: Select all content and then filter. Press c

How to use Excel filter function with multiple conditions How to use Excel filter function with multiple conditions Feb 26, 2024 am 10:19 AM

If you need to know how to use filtering with multiple criteria in Excel, the following tutorial will guide you through the steps to ensure you can filter and sort your data effectively. Excel's filtering function is very powerful and can help you extract the information you need from large amounts of data. This function can filter data according to the conditions you set and display only the parts that meet the conditions, making data management more efficient. By using the filter function, you can quickly find target data, saving time in finding and organizing data. This function can not only be applied to simple data lists, but can also be filtered based on multiple conditions to help you locate the information you need more accurately. Overall, Excel’s filtering function is a very practical

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

See all articles