php多条件组合查询
2024-08-23 01:45:59
- 1. 通过表单把查询条件提交到php文件中,在文件中以post的形式得到传送过来的条件。
- 2. 把传过来的查询条件赋给变量。
- 3. 判断如果查询条件非空,则拼接查询sql。
大体如下:
1.
<form action="" method="post">
条件搜索:<input type="text" name="s_title">
分类搜索:<select name="s_type">
<option value='0'>请选择</option>
<option value='1'>国内</option>
<option value='2'>国际</option>
<option value='3'>军事</option>
<option value='4'>体育</option>
</select>
<input type="submit" value="搜索">
</form>
2.
$title = $_POST[‘s_title’];
$type = $_POST[‘s_type’];
3.
$sqlOrg = “select * from news where”;
if($title != null){
$addTitle = “ and title like ‘%$title%’”;
$sql .= $addTitle;
}
if($type != null){
$addType = “and type = $type”;
$sql .= $addType;
}
最新文章
- PHPnow在win8下安装失败的解决办法
- linux epoll模型
- JAVA实现word doc docx pdf excel的在线浏览 - 仿百度文库 源码
- struts.xml的配置
- [刷题]算法竞赛入门经典(第2版) 5-12/UVa511 - Do You Know the Way to San Jose?
- 龙尚 U9300C wvdial 拨号上网
- IIS命令行静默安装脚本-python
- zigbee 中ZDO的理解
- TCP 三次握爪 四次挥手
- crontab架构和格式
- NodeJs 学习笔记(一)Wedding 项目搭建
- spec 文件详解
- CentOS7安装Java
- How could I create a custom windows message?
- POJ 3678 Katu Puzzle (经典2-Sat)
- MVC初级教程(二)
- Eclipse daemon not running. starting it now on port ***的
- 在Mybatis中使用连表查询的一次实际应用
- python 爬虫(爬取网页的img并下载)
- css-id选择器