/** * Function to search for a task */ function searchWine() { if (isset($_REQUEST['searchWord'])) { include_once '../models/wine.php'; $wine = new Wine(); $searchWord = $_REQUEST['searchWord']; if ($result = $wine->searchWine($searchWord)) { $row = $result->fetch_assoc(); echo '{"result":1, "wines": ['; while ($row) { echo '{"wine_id": "' . $row["wine_id"] . '", "wine_name": "' . $row["wine_name"] . '", "winery_name": "' . $row["winery_name"] . '", "cost": "' . $row["cost"] . '", "wine_type": "' . $row["wine_type"] . '", "year": "' . $row["year"] . '"}'; if ($row = $result->fetch_assoc()) { echo ','; } } echo ']}'; } else { echo '{"result":0,"status": "An error occurred for select product."}'; } } }