所以我在搜索栏上遇到了问题。问题是我从数据库中获取了我的产品,当我尝试搜索它们时,搜索栏仅重定向到produkti页面。但这并没有显示我所期望的下拉列表及其不可链接性。
<?php
include "header.php";
$connect = mysqli_connect("localhost", "root", "majsql", "registration");
if(isset($_POST["add_to_cart"]))
{
if(isset($_SESSION["shopping_cart"]))
{
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
if(!in_array($_GET["id"], $item_array_id))
{
$count = count($_SESSION["shopping_cart"]);
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][$count] = $item_array;
}
else
{
echo '<script>alert("Izdelek je že bil dodan")</script>';
}
}
else
{
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][0] = $item_array;
}
}
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
if($values["item_id"] == $_GET["id"])
{
unset($_SESSION["shopping_cart"][$keys]);
echo '<script>alert("Izdelek odstranjen")</script>';
echo '<script>window.location="kosarica.php"</script>';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div>
<form method="post" action="produkti.php">
<input type="submit" name="manj300" style="margin-top:5px;" class="btn btn-success" value="pod 300€" />
<input type="submit" name="nad300" style="margin-top:5px;" class="btn btn-success" value="nad 300€" />
<input type="submit" name="vsi_izdelki" style="margin-top:5px;" class="btn btn-success" value="vsi izdelki" />
</form>
</div>
<br />
<div class="container">
<br />
<br />
<br />
<br /><br />
<?php
$connect = mysqli_connect("localhost", "root", "majsql", "registration");
$query ="SELECT * FROM tbl_product ORDER BY id ASC";
if(isset($_POST["manj300"])){
$query = "SELECT * FROM tbl_product WHERE price<=300 ORDER BY id ASC";
}
if(isset($_POST["nad300"])){
$query = "SELECT * FROM tbl_product WHERE price>300 ORDER BY id ASC";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{?>
<div class="col-md-4">
<form method="post" action="produkti.php?action=add&id=<?php echo $row["id"]; ?>">
<div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px;" align="center">
<img src="slike/<?php echo $row["image"]; ?>" class="img-responsive" /><br />
<h4 class="text-info"><?php echo $row["name"]; ?></h4>
<h4 class="text-danger">€ <?php echo $row["price"]; ?></h4>
<input type="text" name="quantity" value="1" class="form-control" />
<input type="hidden" name="hidden_name" value="<?php echo $row["name"]; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo $row["price"]; ?>" />
<input type="submit" name="add_to_cart" style="margin-top:5px;" class="btn btn-success" value="Dodaj v košarico" />
</div>
</form>
</div>
<?php
}
}
?>
<div style="clear:both"></div>
<br />
</div>
</div>
<br />
</body>
</html>
<?php
include "footer.php";
?>
并且在searchbar.php中,我现在拥有
<?php
$conn = mysqli_connect('localhost', 'root', '', 'registration', $tbl_product);
if(!isset($_POST['Išči'])) {
header("Location:produkti.php");
}
$search_sql="SELECT * FROM tbl_product WHERE name LIKE '%".$_POST['Išči']."%'";
$search_query=mysql_query($search_sql);
if(mysql_num_rows($search_query) != 0)
{
$search_rs =mysql_fetch_assoc($search_query);
}
?>
预期结果就像当我在搜索栏中编写asus时,它会下拉所有asus产品。在我的示例中,当我单击其中的一个将其重定向到他的页面时,我有3种产品,带有asus的一种将被重定向到页面p1.php。