I have an index.php file where I instantiate the D...
# community-help
k
I have an index.php file where I instantiate the DB class and use the methods. Do I need to add anything else here? I think I'm doing the search correctly ...
<?php
require 'vendor/autoload.php';
require './SearchDB/DB.php';
use Dotenv\Dotenv;
use SearchDB\DB;
$dotenv = Dotenv::createImmutable(__DIR__, '.env.development');
$dotenv->load();
$db = new DB();
$db->getProductQueries();
if (isset($_GET['q'])) {
$searchResults = $db->search($_GET['q']);
$products = $searchResults['products'];
$facets = $searchResults['facets'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Results</title>
</head>
<body>
<form action="" method="GET">
<input type="text" name="q" placeholder="Search for products" value="<?= isset($_GET['q']) ? $_GET['q'] : '' ?>">
<button type="submit">Search</button>
</form>
<ul>
<?php if (!empty($products)) : ?>
<?php foreach ($products as $product) : ?>
<li><?= $product['document']['id'] ?> - <?= $product['document']['manufacturer_id'] ?></li>
<?php endforeach; ?>
<?php else : ?>
<li>No results found</li>
<?php endif; ?>
</ul>
</body>
</html>