[英]php search bar when I press submit with nothing in the search bar it shows all the data
[英]php search bar: how can I clear entries, when clearing search bar
這是我在這里的第一個貢獻:
所以我使用的是 PHP 和 MySQLi。 我有一個搜索欄,效果很好,但是當我清除搜索時,我希望條目消失。
使用搜索欄正在更改 URL:
無搜索: http://localhost:52694/index.php
搜索: http://localhost:52694/index.php?search=test
If I clear my search bar, it is still the same URL ( http://localhost:52694/index.php?search=test
) and I cant click go
because it tells me that the box can't be empty to start search .
我希望一切都清楚,你理解我的問題。
這是我在 php 代碼中的搜索:
<?php
if(isset($_GET['search'])){
$filtervalues = $_GET['search'];
$query = "SELECT * FROM table WHERE CONCAT( value, name, zla ) LIKE '%$filtervalues%' ";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) > 0) {
foreach($query_run as $items) {
?>
<tr>
<td><?= $items['value']; ?></td>
<td><?= $items['name']; ?></td>
<td><?= $items['zla']; ?></td>
<td>
<a class='btn btn-danger btn-sm' href='/delete.php?id=<?php echo $items['id']; ?>'>Del</a>
</td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="4">No Record Found</td>
</tr>
<?php
}
}
?>
從
我無法單擊 go 因為它告訴我該框不能為空以開始搜索。
我假設在您的 HTML 中,您的輸入字段中存在必需的屬性。 這是一個使用 required 的示例:
<form action="index.php" method="GET">
Search for : <input name="search" required/>
<input type="submit" value="send"/>
</form>
<?php
if(isset($_GET["search"]))
echo $_GET["search"];
else
echo "nothing to search for";
使用這樣的示例:如果您的搜索字段為空,則會彈出一個小框告訴您填寫該字段。
因此,請簡要介紹您的 html 搜索條碼,或檢查是否存在需要,如果存在.. 將其刪除,並將其僅用於必須填寫的字段,如登錄或...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.