当前位置:网站首页>PHP高级检索功能的实现以及动态拼接SQL
PHP高级检索功能的实现以及动态拼接SQL
2022-08-05 11:08:00 【智慧浩海】
PHP高级检索功能的实现以及动态拼接sql总结。完成的功能有:可以单独根据一个条件查询,也可以通过多个条件综合查询,难点在于动态拼接sql。完成的效果总画面 单独根据姓名模糊查询 根据多个条件综合查询 前台页面代码 后台处理代码 动,下方主要介绍关于php 高级检索及sql拼接的全文内容,希望对你有所帮助。
PHP高级检索功能的实现以及动态拼接sql总结。完成的功能有:可以单独根据一个条件查询,也可以通过多个条件综合查询,
难点在于动态拼接sql。
完成的效果
总画面

单独根据姓名模糊查询

单独根据性别查询

根据多个条件综合查询

前台页面代码
<form action="" method="post">
<labal>姓名:</labal> <input style="width:105px" type="text" name="search_name" id="search_name" placeholder="姓名">
 
<labal>性别:</labal>
<input type="radio" name="search_sex" id="man" value="0">男
<input type="radio" name="search_sex" id="women" value="1">女
 
<labal>年龄:</labal><input style="width:105px" type="text" name="search_age" id="add_age"placeholder="年龄">
 
<labal>邮箱:</labal><input style="width:150px" type="text" name="search_email" id="search_email" placeholder="邮箱">
<input id="b" name="submit" style="width:60px" type="submit" value="检索">
</form>
后台处理代码
//接收用户输入的数据
$name = $sex = $age = $email = "";
if (isset($_POST['submit'])) {
if (isset($_POST['search_name'])) {
$name = $_POST['search_name'];
}
if (isset($_POST['search_sex'])) {
$sex = $_POST['search_sex'];
}
if (isset($_POST['search_age'])) {
$age = $_POST['search_age'];
}
if (isset($_POST['search_email'])) {
$email = $_POST['search_email'];
}
//执行检索sql
$search_sql = $myTest->searchData($name,$sex,$age,$email);
$result = $myTest->sqlRun($search_sql);
动态拼接sql
public function searchData($name,$sex,$age,$email){
switch ($name) {
//未输入姓名
case null:
$name_info='';
break;
//根据姓名模糊查询
default:
$name_info=" and name LIKE '%".$name."%'";
break;
}
switch ($sex) {
//未输入性别
case null:
$sex_info='';
break;
//根据性别准确查询
default:
$sex_info=' and sex='.$sex;
break;
}
switch ($age) {
//未输入年龄
case null:
$age_info='';
break;
//根据年龄准确查询
default:
$age_info=' and age='.$age;
break;
}
switch ($email) {
//未输入邮箱
case null:
$email_info='';
break;
//根据邮箱模糊查询
default:
$email_info=" and email LIKE '%".$email."%'";
break;
}
$search_sql='SELECT * FROM users WHERE 1=1'.$name_info.$sex_info.$age_info.$email_info;'';
return $search_sql;
}边栏推荐
- Google启动通用图像嵌入挑战赛
- CenOS MySQL入门及安装
- 时间格式2020-01-13T16:00:00.000Z中的T和Z分别表示什么,如何处理
- 012年通过修补_sss_提高扩散模型效率
- Linux: Remember to install MySQL8 on CentOS7 (blog collection)
- Http-Sumggling缓存漏洞分析
- Image segmentation model - a combination of segmentation_models_pytorch and albumations to achieve multi-category segmentation
- The host computer develops C# language: simulates the STC serial port assistant to receive the data sent by the microcontroller
- lvgl 实现状态提示图标自动对齐补位显示
- Mathcad 15.0软件安装包下载及安装教程
猜你喜欢

并非富人专属,一文让你对NFT改观

金融业“限薪令”出台/ 软银出售过半阿里持仓/ DeepMind新实验室成立... 今日更多新鲜事在此...

再获殊荣 | 赛宁网安入选2022年度“培育独角兽”企业榜单

数据可视化(二)

Android development with Kotlin programming language II Conditional control

DocuWare平台——文档管理的内容服务和工作流自动化的平台详细介绍(下)

化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)

.NET深入解析LINQ框架(六:LINQ执行表达式)

The host computer develops C# language: simulates the STC serial port assistant to receive the data sent by the microcontroller

012_SSS_ Improving Diffusion Model Efficiency Through Patching
随机推荐
poj2935 Basic Wall Maze (2016xynu暑期集训检测 -----D题)
Login function and logout function (St. Regis Takeaway)
trie树模板
记2022年七夕感慨
Google启动通用图像嵌入挑战赛
Image segmentation model - a combination of segmentation_models_pytorch and albumations to achieve multi-category segmentation
Naive bayes
.NET深入解析LINQ框架(六:LINQ执行表达式)
发现C语言的乐趣
PG优化篇--执行计划相关项
Student Information Management System (first time...)
拓朴排序例题
一张图看懂 SQL 的各种 join 用法!
[Android] How to use RecycleView in Kotlin project
CenOS MySQL入门及安装
Integration testing of software testing
软件测试之集成测试
Go学习笔记(篇二)初识Go
HDD杭州站•ArkUI让开发更灵活
【C语言指针】用指针提升数组的运算效率