栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

带有连接的搜索查询在搜索到的字符串为空时显示所有行

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

带有连接的搜索查询在搜索到的字符串为空时显示所有行

请注意,
您的代码对SQL注入相关的攻击开放。请学习使用预备报表

现在,我们将需要

WHERe
动态生成查询的一部分。我们可以使用
!empty()
函数检查输入的过滤器值是否不为空,然后将其条件动态添加到查询中。

$functie = $_POST['functie'];$branche = $_POST['branche'];$regio = $_POST['regio'];$search = "SELECt cnt.title, cnt.alias, cnt.images, cnt.introtext, cnt.catid, cat.title, cat.aliasFROM snm_content cntLEFT JOIN snm_categories catON cat.id = cnt.catid ";// Collect all the where conditions in an array$whr = array();// check if $functie has some value in input filterif (!empty($functie)) {    $whr[] = "cnt.title LIKE '%" . $functie . "%'";}// check if $branche has some value in input filterif (!empty($branche)) {    $whr[] = "cat.title LIKE '%" . $branche . "%'";}$where_sql = '';// Prepare where part of the SQLif (!empty($whr)) {    $where_sql = ' WHERe ' . implode(' OR ', $whr);}// Append to the original sql$search .= $where_sql;


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/390454.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号