PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-在单元格中搜索字符串大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我在下图所示的数据库中保存了用逗号分隔的不同功能
当我选择一个这样的功能

SELECT rt.*, rb.*, rf.*, rs.*
FROM business rt
INNER JOIN business_company_info rb
ON rt.id=rb.business_id
INNER JOIN business_attributes rf
ON rt.id=rf.business_id
INNER JOIN business_basic_info rs
ON rt.id=rs.business_id
WHERE business_keyword LIKE '%3000%' AND features LIKE '%feature3%' and
status= 0 ORDER BY rt.id DESC

数据是从数据库获取的,但是当我具有许多功能时,它将无法搜索.
这是我查询的许多功能查询

SELECT rt.*, rb.*, rf.*, rs.*
FROM business rt
INNER JOIN business_company_info rb
ON rt.id=rb.business_id
INNER JOIN business_attributes rf
ON rt.id=rf.business_id
INNER JOIN business_basic_info rs
ON rt.id=rs.business_id
WHERE business_keyword LIKE '%3000%' AND features LIKE'%feature3,feature2,feature4%' and
status= 0 ORDER BY rt.id DESC

这是我的代码.

if(isset($_POST['advance_search']) && !empty($_POST['advance_search']) && ((isset($_POST['area']) && !empty($_POST['area']))  || 
                            (isset($_POST['salary']) && !empty($_POST['salary'])) || (isset($_POST['industry']) && !empty($_POST['industry'])) || (isset($_POST['jobtype']) && !empty($_POST['jobtype'])) 
                            || (isset($_POST['keyword']) && !empty($_POST['keyword'])) || (isset($_POST['empnum']) && !empty($_POST['empnum'])) || (isset($_POST['year']) && !empty($_POST['year'])) 
                            || (isset($_POST['features']) && !empty($_POST['features'])) || (isset($_POST['employ_status']) && !empty($_POST['area']))
                            )){
                                //echo '<pre>';print_r($_POST);exit;
                                $area = $_POST['area'];
                                $salary = $_POST['salary'];
                                $industry = $_POST['industry'];
                                $jobtype = $_POST['jobtype'];
                                $keyword = $_POST['keyword'];
                                $empnum = $_POST['empnum'];
                                $year = $_POST['year'];

                                //echo '<pre>';print_r($ids);print_r($salary);print_r($keyword);print_r($jobtypE);print_r($industry);exit;
                                //echo '<pre>';print_r($area);print_r($salary);print_r($industry);print_r($jobtypE);print_r($keyword);print_r($empnum);print_r($year);exit;
                                /*if(isset($_POST['genre'])){
                                    $genres_search = implode(',', $_POST['genre']);
                                }*/
                                if(isset($_POST['employ_status'])){
                                    $employment_search = implode(',', $_POST['employ_status']);
                                }
                                if(isset($_POST['features'])){
                                    $features_search = implode(',', $_POST['features']);
                                }

                                $conditions = array();
                                if (!empty($area)){
                                    $conditions[] = "business_LOCATIOn LIKE '%$area%'";
                                }
                                if (!empty($salary)){
                                    $conditions[] = "business_salary_rule LIKE '%$salary%'";
                                }
                                if (!empty($keyword)){
                                    $conditions[] = "business_keyword LIKE '%$keyword%'";
                                }
                                if (!empty($jobtypE)){
                                    $conditions[] = "business_job_type >= '$jobtype'";
                                }
                                if (!empty($industry)){
                                    $conditions[] = "business_induStries LIKE '%$industry%'";
                                }
                                if (!empty($empnum)){
                                    $conditions[] = "employees_number LIKE '%$empnum%'";
                                }
                                if (!empty($year)){
                                    $conditions[] = "established_year LIKE '%$year%'";
                                }
                                if (!empty($employment_search)){
                                    $conditions[] = "employment_status LIKE '%$employment_search%'";
                                }
                                if (!empty($features_search)){
                                $conditions[] = "features LIKE '%$features_search%'";
                                }

                                $sql = "SELECT rt.*, rb.*, rf.*, rs.*
                                    FROM business rt
                                    INNER JOIN business_company_info rb
                                    ON rt.id=rb.business_id
                                    INNER JOIN business_attributes rf
                                    ON rt.id=rf.business_id
                                    INNER JOIN business_basic_info rs
                                    ON rt.id=rs.business_id
                                    WHERE ". implode(' AND ', $conditions) . " and
                                    status= 0 ORDER BY rt.id DESC"; echo '<pre>';print_r($sql);exit;

                           }

任何帮助,将不胜感激.谢谢

解决方法:

您可以分解$feature并将其存储到数组中.
这样的事情.

if (!empty($features_search))
{
    $feature_array= explode(",", $features_search);
    for each($feature_array as $key => $featurE)
    {
        $conditions[] = "features LIKE '%$feature%'";
    }
}

希望能有所帮助.

大佬总结

以上是大佬教程为你收集整理的php-在单元格中搜索字符串全部内容,希望文章能够帮你解决php-在单元格中搜索字符串所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: