SWDW_Fruit_Store/indexes/search/search_item.php
2025-06-06 17:14:52 +08:00

52 lines
1.5 KiB
PHP

<link rel="stylesheet" href="./search.css" type="text/css" />
<script src="./iframe.js"></script>
<?php
include "../ConnectDB.php";
session_start();
$usertype = mysqli_real_escape_string($conn, $_SESSION['user_type']);
if ($usertype == 'seller') {
$m = "seller_price";
} else {
$m = "buyer_price";
}
if(isset($_GET["text"])) {
$name = $_GET["text"];
if($name == null){
return;
}
$sql_find = "SELECT DISTINCT * FROM inventory WHERE name LIKE '%{$name}%' GROUP BY id";
$res = mysqli_query($conn, $sql_find);
$row = mysqli_num_rows($res);
$goods = mysqli_fetch_assoc($res);
if(!$goods){
echo '<h1 style="text-align: center;">item not found</h1>';
return;
}
echo '<div id="grid">';
for ($i = 0; $i < $row; $i++) {
echo '<table id="items">';
echo '<tr>';
echo '<td width="25%">';
echo '<img src="data:image/jpeg;base64,' . base64_encode($goods['img']) . '" id="' . $goods['name'] . '" onclick="details(this)">';
echo '</td>';
echo '<td width="50%">';
echo '<h4 style="margin: 0%;" id="' . $goods['name'] . '" onclick="details(this)">' . $goods['name'] . '</h4>';
echo '</td>';
echo '<td width="25%">';
echo '<p style="margin: 0%;" >¥' . $goods[$m] . '/kg</p>';
echo '</td>';
echo '</tr>';
echo '</table>';
}
echo '</div>';
}
else{
return;
}
?>