单击搜索时,会显示数据,但是当我再次单击时,数据会消失。我知道这很简单,但我真的无法弄明白。我试图尽可能多地解释。
Search Engine: <input type="text" name="search" placeholder="Enter keywords..." />
<input type="submit" name="search_product" value="Search now"/>
</form>
mysql_connect("localhost", "root", "");
mysql_select_db("tutorial");
if(empty($_GET['search'])){
echo "No Search results";
}
if(!empty($_GET['search'])){
if (isset($_GET['search_product'])){
$search_value = $_GET['search'];
$query = "SELECT * FROM `blob` WHERE keyword LIKE '%$search_value%'";
$run = mysql_query($query);
while($row = mysql_fetch_array($run)){
$name = $row['name'];
$categorie = $row['categorie'];
$lieu = $row['lieu'];
$image = $row['image'];
echo ("<div style='text-align:center;' style=width:300px; align='center';><h2><p>Nom du Produit: $name</h2> <strong>Categorie:</strong> $categorie <p><strong>Lieu:</strong> $lieu </p></p></div>");
echo "<div style='margin-left:630px;'>";?><?php echo"<img src=$image <height='150' width='150'>"?> <?php echo "</div>";
echo "<hr/>";
}
}
}
答案 0 :(得分:0)
只需回显搜索数据$search_value = $_GET['search']
再次单击搜索按钮。
如果您没有在$search_value
中获得任何数据,那么在查询中您将找不到任何数据。
答案 1 :(得分:0)
<?php
if(isset($_GET['search']) && !empty($_GET['search']) )
{
$var = $_GET['search'];
echo $var;//var_dump($var);
echo '</br>';
}
if(isset($_GET['search']) && empty($_GET['search']) )
{
echo "empty";
}
?>
<form action = "" method = "GET">
<input type="text" name="search" placeholder="Enter keywords..." />
<input type="submit" name="search_product" value="Search now"/>
</form>
我正在向您展示一个可能对您有帮助的演示。