我有一个代码,可以动态显示数据库中的书籍类别。我想现在添加另一个功能,如果我点击下拉列表中的任何类别,它应该显示该类别的产品。但我已经有一个显示数据库书籍的主页。我只希望能够点击该类别并更改该特定类别的产品。 这是下拉列表的代码:
<?php include "connection.php";
$writer_query="SELECT * FROM writer LIMIT 0,5";
$run_query= mysqli_query($conn, $writer_query);
if(mysqli_num_rows($run_query)>0){
while($row=mysqli_fetch_array($run_query)){
$wid=$row["w_id"];
$wname=$row["w_name"];
echo"
<a class='nav-link bottom' id='v-pills-profile-tab' data-toggle='pill' href='#v-pills-profile' role='tab' aria-controls='v-pills-profile' aria-selected='false'>$wname</a>
";
}}
?>
以下是我在主页上显示图书的代码:
<div class="card-body">
<div class="card-deck">
<?php include"connection.php";
$book_query="SELECT b.*, w.* FROM books as b INNER JOIN writer as w on b.b_writer = w.w_id ORDER BY RAND() LIMIT 8";
$run_query= mysqli_query($conn, $book_query);
if(mysqli_num_rows($run_query)>0){
while($row=mysqli_fetch_array($run_query)){
$bid=$row["b_id"];
$bname=$row["b_name"];
$bisbn=$row["b_isbn"];
$bwriter=$row["w_name"];
$bprice=$row["b_price"];
$bdesc=$row["b_desc"];
$bimg=$row["b_img"];
?>
<div class="col-md-3 col-sm-6 mt-4">
<div class="card text-center ">
<img class="card-img-top img-thumbnail img-thumb" src="<?php echo"$bimg";?>" alt="Dune">
<div class="card-body">
<h6 class="card-title"><?php echo"$bname";?></h6>
<footer class="blockquote-footer">By <cite title="<?php echo $bwriter;?>"><?php echo"$bwriter";?></cite></footer>
<p class="card-text">Price: ₹ <?php echo"$bprice";?></p>
<a href="#" class="btn btn-primary" data-toggle="modal" data-target="#buy">Buy</a>
<input type="button" value="Details" id="<?php echo $row["b_id"]; ?>" class="btn btn-primary view_data" />
</div>
</div>
</div>
<?php }} ?>
</div>
</div>
答案 0 :(得分:0)
您需要将类别ID存储到锚标记中。 像http://www.example.com/home?cat_id=2
一样通过使用此功能,您可以在另一个页面上获取该类别ID并获取URL的参数。
现在你需要wrire代码和查询
If(!empty(cat_id)) {
//, HERE IS YOUR QUERY AND RETURN ARRAY
}