Searchproduct.php 877 B

123456789101112131415161718192021222324
  1. <?php
  2. include "conn.php";
  3. checkLogin("信息管理");
  4. $str = textEncode($_GET['str'] ?? '');
  5. $sql = "SELECT p.id, p.ProductImg, p.ProductName, p.unit, p.category_id, pc.name as categoryName
  6. FROM products p
  7. LEFT JOIN product_categories pc ON p.category_id = pc.id
  8. WHERE p.productName LIKE '%" . $str . "%'";
  9. $rs = $conn->query($sql);
  10. while ($row = $rs->fetch_assoc()) {
  11. $categoryDisplay = !empty($row['categoryName']) ? ' <span style="color:#888;font-size:12px;">['.$row['categoryName'].']</span>' : '';
  12. ?>
  13. <li data-id="<?php echo $row['id']; ?>" data-unit="<?php echo $row['unit']; ?>">
  14. <div class="list-content">
  15. <div class="pic"><img src="<?php echo $row['ProductImg']; ?>" ></div>
  16. <div class="name"><?php echo $row['ProductName']; ?><?php echo $categoryDisplay; ?></div>
  17. </div>
  18. </li>
  19. <?php
  20. }
  21. ?>