 <?php
include('connection.php');
$con = getdb();
$search = @$_POST['search'] ?: @$_GET['search'];

$qr = "";
if ($search != "") {
    $qr = $qr . "AND (test.UPC LIKE '%$search%' OR test.Product LIKE '%$search%' OR test.Vendor LIKE '%$search%' OR test.Price LIKE '%$search%' OR test.VendorName LIKE '%$search%')";
}

$htmlResult = "<div class='table-responsive'>
    <table id='myTable' class='table table-striped table-bordered'>
    <thead>
        <tr>
            <th>UPC</th>
            <th>Product</th>
            <th>Vendor</th>
            <th>Price</th>
        </tr>
    </thead>
    <tbody>";

    $result = mysqli_query($con, "SELECT * from (SELECT * , (SELECT vendor.VendorName FROM vendor WHERE id = test_table.vendor ) as VendorName FROM test_table) as test WHERE test.UPC != '' $qr ORDER BY test.Price ASC") or die(mysql_error());


if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        
       $htmlResult .= "<tr>
                <td>" . $row['UPC'] . "</td>
                <td>" . $row['Product'] . "</td>
                <td>" . $row['VendorName'] . "</td>
                <td>" . $row['Price'] . "</td>
            </tr>";
    }
} else {
    $htmlResult .= "<h4 style='text-align:center'>No results found for the search criteria.</h4>";
}

$htmlResult .= "</tbody></table></div>";

echo $htmlResult;
?>