如何制作一个按价格对产品进行升序和降序排序的按钮

时间:2020-07-10 00:02:58

标签: php sql ajax

您好,我想创建两个按钮,一个用于升序,另一个用于降序产品。当我单击按钮时,产品需要分类。这是我的代码,如何制作按钮?谢谢

<?php
include("pagination/function.php");
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 4; 
$startpoint = ($page * $limit) - $limit;
$statement = "product WHERE product_category='Men'"; 
$res=mysqli_query($link,"select * from product {$statement} LIMIT {$startpoint} , {$limit}");
while ($row=mysqli_fetch_array($res))
{
?>

<div class="column">

 <div class="card1">
   <a href="products/product_details.php?id=<?php echo $row['id']; ?>">
 <img src="./<?php echo $row["product_image"]; ?>"  style="width:100%" ></a>
 <h1><?php echo $row["product_name"]; ?></h1>
 <p class="price">€<?php echo $row["product_price"]; ?></p>

 </div>

 </div>


 <?php
 }

 ?>


 </div>
 </div>
 <?php

 include 'pagination/pagenumber2.php';

  ?>

因此,通过单击按钮,我需要更改此代码

$statement = "product WHERE product_category='Men'";
$res=mysqli_query($link,"select * from product {$statement} LIMIT {$startpoint} , {$limit}");

此代码

    $statement = "product WHERE product_category='Men' ORDER BY product_price DESC";
$res=mysqli_query($link,"select * from product {$statement} LIMIT {$startpoint} , {$limit}");

0 个答案:

没有答案