【问题标题】:tutorials refine or filter a php search教程 优化或过滤 php 搜索
【发布时间】:2014-03-09 23:39:08
【问题描述】:

有谁知道在搜索完成后如何细化过滤 php/mysql 搜索的任何教程?我已经搜索了谷歌和所有可能的搜索引擎,但没有。

提前谢谢你

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

【问题讨论】:

  • 您是否在寻求进一步过滤已完成的查询结果的方法?
  • 您使用的development framework 是否有此插件?也许你应该是?
  • 哇,你已经完成了很多搜索!你能告诉我们你的 php/mysql 搜索的代码吗?
  • @useSticks yes 来过滤已进行的查询

标签: php mysql search filter


【解决方案1】:

This blog 有一个部分简要概述了过滤来自 MYSQLi 的返回。有关更多详细信息,我建议查看 MYSQLiPDO 文档。

(当然,我真正推荐的是查看众多 PHP 框架之一!- 我看到 tadman 已经在 cmets 中提供了一个很好的列表链接。)

【讨论】:

    猜你喜欢
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    相关资源
    最近更新 更多