如果用户没有在下拉菜单中选择任何内容或选择他在那里选择的内容,我将尝试从我的数据库中选择所有内容。所以基本上我想做的是检查$filter是否为空,如果是,则选择所有内容,但不知道如何做到这一点。下面是我的select,如果我从下拉列表中选择某个内容,它会很好地工作,但是在我选择某个内容之前,它会给出一个未定义的索引警告。
<?php
$visibility = 1;
$filter = $_GET['slct'];
$stmt = $conn->prepare("SELECT id, name, description, address, phone, phone2, email, company, job, visibility, filter, confirmed, userid FROM cards WHERE visibility = ? AND filter = ?");
$stmt->bind_param("is", $visibility, $filter);
$stmt->execute();
$result = $stmt->get_result();
while ($record = mysqli_fetch_assoc($result)) {
?>
然后选择:
<select name="slct" id="slct" onchange="form.submit()">
<option value="One">One</option>
<option value="Two">Two</option>
</select>
1条答案
按热度按时间dw1jzc5e1#
首先获得全球
slct
```$visibility = 1;
$filter = isset($_GET['slct']) ? $_GET['slct'] : "";
$baseQuery = "SELECT id, name, description, address, phone, phone2, email, company, job, visibility, filter, confirmed, userid FROM cards WHERE visibility = ?" ;
$filterPart = isset($_GET['slct']) ? " AND filter = ?" : "";
$stmt = $conn->prepare( $baseQuery. $filterPart);
if(isset($_GET['slct'])){
$stmt->bind_param("is", $visibility, $filter);
}else{
$stmt->bind_param("is", $visibility);
}
$stmt->execute();