您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

$functie = $_POST['functie'];
$branche = $_POST['branche'];
$regio = $_POST['regio'];

$search = "
SELECT cnt.title, cnt.alias, cnt.images, cnt.introtext, cnt.catid, cat.title, cat.alias
FROM snm_content cnt
LEFT JOIN snm_categories cat
ON cat.id = cnt.catid ";

// Collect all the where conditions in an array
$whr = array();

// check if $functie has some value in input filter
if (!empty($functie)) {
    $whr[] = "cnt.title LIKE '%" . $functie . "%'";
}

// check if $branche has some value in input filter
if (!empty($branche)) {
    $whr[] = "cat.title LIKE '%" . $branche . "%'";
}

$where_sql = '';
// Prepare where part of the sql
if (!empty($whr)) {

    $where_sql = ' WHERE ' . implode(' OR ', $whr);
}

// Append to the original sql
$search .= $where_sql;
其他 2022/1/1 18:53:31 有489人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶