簡體   English   中英

教程優化或過濾php搜索

[英]tutorials refine or filter a php search

有誰知道在完成搜索后如何優化過濾php / mysql搜索的任何教程? 我已經搜索過Google和所有可能的搜索引擎,但是什么也沒有。

先感謝您

<?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);
}

?>

以下輸出結果

<?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  }  ?>

該博客的一節提供了有關過濾MYSQLi回報的簡要概述。 有關更多詳細信息,建議您查看MYSQLiPDO文檔。

(當然,我真正推薦的是檢查PHP的眾多框架之一!-我看到tadman已經在注釋中提供了指向它們的良好列表的鏈接。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM