简体   繁体   中英

How to establish mysql select queries for multiple conditions in a site search engine

I am attempting to create a site search engine on a site. The image below is an example of the query form:

在此处输入图片说明

The client can select all or just one of the options available... what i do not understand is how to query the database not knowing what options the client is going to select.

Any assistance is appreciated.

You would use an if(){} for each condition to create the sql select query

if($varA == 'whatever' && $varB == 'whatever){$sql = 'SELECT AAA,BBB FROM THETABLE WHERE AAA=:THEID ORDER BY whatever'}
elseif($varA == 'whatever' && $varB == 'whatever){$sql = 'SELECT AAA,BBB FROM THETABLE WHERE AAA=:THEID ORDER BY whatever'}


    $selectqup = $db->prepare($sql);    
    $selectqup->bindValue(':THEID',$AAA,PDO::PARAM_INT);$selectqup->execute(); 
    $ct = $selectqup->rowCount();   

        while($row = $selectqup->fetch(PDO::FETCH_ASSOC)){
        $??? = $row['???'];
        $??? = $row['???'];

        // run serps here

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM