gpt4 book ai didi

php - 教程优化或过滤 PHP 搜索

转载 作者:行者123 更新时间:2023-11-30 23:06:22 25 4
gpt4 key购买 nike

有谁知道关于如何在搜索完成后优化或过滤 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 } ?>

最佳答案

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

(当然,我真正推荐的是检查众多 PHP 框架中的一个!- 我看到 tadman 已经在评论中提供了指向这些框架的良好列表的链接。)

关于php - 教程优化或过滤 PHP 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21714498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com