简体   繁体   中英

tutorials refine or filter a php search

Does anyone knows any tutorials on how to refine of filter a php/mysql search after the search has already been made? I have searched google and every possible search engine out there, but nothing.

Thank you in advance

<?php
if(isset ($_POST['searchString'])){

    $searchStr = $_POST['searchString'];

    function sanitizeString($searchStr){
        $searchStr = htmlentities($searchStr);
        $searchStr = strip_tags($searchStr);
        $searchStr = htmlspecialchars($searchStr);
        return $searchStr;
    }

    $searchStr = sanitizeString($searchStr);
    $searchStr = str_replace("%", "", $searchStr);
    require_once('Connections/conn.php');


$sql = "SELECT * FROM happyhours
WHERE city LIKE :keyword OR zipcode LIKE :keyword";



    if (!empty($searchStr)){

        $stmt=$conn->prepare($sql);
        $stmt->bindParam(':keyword',$searchStr, PDO::PARAM_STR);

            try{
                $stmt->execute();
                }
            catch(PDOException $ex){
                echo $ex->getMessage();
                }
    }
        $count = $stmt->rowCount();
        $each = $stmt->fetch(PDO::FETCH_ASSOC);
}

?>

the following to output results

<?php do { ?>

<table id="results" align="left" width="700px" border="0">
      <tr>
        <td rowspan="5" width="130" id="photo"><a class="lightbox" href='<?php echo $each['imageURL']; ?>'><p><?php echo $each['name']; ?></p><img id="hh-image" src='<?php echo $each['imageURL']; ?>' width="80" height="80" /></a></td>

        <tr><td id="hh-name" style="word-wrap:break-word; font-size:16px; font-family:'Myriad Pro'; font-weight:500" width="560" height="20"><?php echo $each['name']; ?></td></tr>

         <tr><td> <a href='<?php echo $each['googleMap']; ?>' target="new" style="font-size:14px"><?php echo $each['address']; ?></a></td>
      </tr>
      <tr>
        <td style="word-wrap:break-word; font-size:14px; font-family:'Myriad Pro'" height="20"><?php echo $each['phone']; ?></td>
      </tr>
      <tr>
        <td style="word-wrap:break-word; font-size:14px; font-family:'Myriad Pro'" height="20"><?php echo $each['dayOfTheWeek']; ?>&nbsp;&nbsp;(<?php echo $each['hours']; ?>)</td>
      </tr>
    </table>
    <br/>


<?php } while($each = $stmt->fetch(PDO::FETCH_ASSOC)); ?>



<?php  }  ?>

This blog has a section that provides a brief overview on filtering a return from MYSQLi. For more detail, I'd suggest checking the MYSQLi or PDO documentation.

(Of course, what I'd really recommend is checking out one of the many frameworks for PHP! - I see that tadman has already provided a link to a good list of them in the comments.)

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