我在下面添加了我的代码,我是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" ;
}
} ?&GT;
答案 0 :(得分:1)
只需在页面中添加。
<强> CSS:强>
.highlight{background-color:yellow}
<强> jQuery的:强>
$("body").highlight("<?php echo $search; ?>");