只需应用您拥有的同一个div,并在while块中应用所获取的值即可。
串连必要当值:
<?php
$output = '';
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysql_query("SELECT * FROM recipe WHERE recipeName LIKE '%$searchq%' OR recipe_ing1 LIKE '%$searchq%' ") or die("Could not search.");
$count = mysql_num_rows($query);
if($count == 0) {
$output = 'There was mo match!';
} else {
while($row = mysql_fetch_array($query)){
$rN = $row['recipeName'];
$output .= '
<div class="panel panel-default">
<div class="panel-heading"><b>' . htmlentities($rN, ENT_QUOTES) . '</b></div>
</div>
';
}
}
}
?>
<form action = "search.php" method = "post">
<input type = "text" name = "search" placeholder = "Search for recipes..."/>
<input type = "submit" value = ">>" />
</form>
<?php echo $output; ?>
非常感谢!我一直试图在最近2个小时内解决这个问题,上帝知道它为什么没有工作。再次感谢 – Nevershow2016
@ Nevershow2016作为旁注,你很容易受到sql注入的影响,很高兴这有助于 – Ghost