【问题标题】:How to highlight user input in mysql search results using php?如何使用 php 在 mysql 搜索结果中突出显示用户输入?
【发布时间】:2018-04-07 19:31:36
【问题描述】:

我在下面添加了我的代码,我是 php 和 mysql 的新手,并尝试根据用户输入使用 php 搜索 mysql,并且工作得很好。但不确定如何在从 mysql 显示时突出显示用户输入值。

$output = NULL;
if(isset($_POST['submit'])){
$mysqli = new mysqli("localhost","root","","test");
$search = $mysqli->real_escape_string($_POST['search']);
$resultSet = $mysqli->query("SELECT * FROM books WHERE BookContent LIKE '%$search%'");
if($resultSet->num_rows>0){
    while($rows = $resultSet->fetch_assoc()){
        $BookContent = $rows['BookContent'];
        //$output = preg_replace("/($search)/i",'<span class="highlight">$1</span>', $output);
        echo $output = "" ."Your search results-->  $BookContent"."<br>";
    }

}else{
    echo $output = "No result" ;
}

} ?>

【问题讨论】:

标签: php html mysql


【解决方案1】:

只需将其添加到您的页面中即可。

CSS:

.highlight{background-color:yellow}

jQuery:

$("body").highlight("<?php echo $search; ?>");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 2023-03-22
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    相关资源
    最近更新 更多