Editing: voice-search.php
<?php include_once("config/config.php"); $base_url = "https://yourdomain.com/"; // Replace with your domain $q = isset($_GET['q']) ? trim($conn->real_escape_string($_GET['q'])) : ''; if ($q === '') { echo "<p>No search term provided.</p>"; exit; } $normalized_q = strtolower(str_replace(' ', '', $q)); // Unified Search Function function searchBothSources($term, $conn) { $term = strtolower(str_replace(' ', '', $term)); $results = []; // Search Ads $ads_sql = "SELECT id, ad_title AS title, location, image, 'ad' AS type FROM ad_form WHERE REPLACE(LOWER(ad_title), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(description), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(email), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(phone), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(user_name), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(asking_price), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(category), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(subcategory), ' ', '') LIKE '%$term%' LIMIT 10"; $ads = $conn->query($ads_sql); if ($ads && $ads->num_rows > 0) { while ($row = $ads->fetch_assoc()) { $results[] = $row; } } // Search Blogs $blogs_sql = "SELECT id, title, author_name AS location, image, 'blog' AS type FROM blog_posts WHERE REPLACE(LOWER(title), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(description), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(email), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(phone), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(category_id), ' ', '') LIKE '%$term%' OR REPLACE(LOWER(author_name), ' ', '') LIKE '%$term%' LIMIT 10"; $blogs = $conn->query($blogs_sql); if ($blogs && $blogs->num_rows > 0) { while ($row = $blogs->fetch_assoc()) { $results[] = $row; } } return $results; } function displayResults($results, $title, $base_url) { echo "<div style='flex: 1;'>"; echo "<h4 style='color: white;'>$title</h4>"; if (empty($results)) { echo "<p style='color: white;'>No results found.</p>"; } else { foreach ($results as $row) { $type = ucfirst($row['type']); $link = $base_url . ($type === 'Ad' ? "single-ad.php?id=" : "single-blog.php?id=") . $row['id']; echo "<div class='search-result-item'>"; echo "<a href='$link' style='color: white; display: block; margin: 10px 0;'>"; echo "<strong>" . htmlspecialchars($row['title']) . "</strong><br>"; echo "<small>" . htmlspecialchars($row['location']) . " <em style='color: #ccc;'>($type)</em></small>"; echo "</a></div>"; } } echo "</div>"; } // Layout start echo "<div style='display: flex; gap: 40px;'>"; // Exact match $exactResults = searchBothSources($q, $conn); displayResults($exactResults, "Exact Match", $base_url); // Keyword-related $keywords = explode(' ', $q); if (count($keywords) > 1) { $word1Results = searchBothSources($keywords[0], $conn); displayResults($word1Results, "Related to \"" . htmlspecialchars($keywords[0]) . "\"", $base_url); $word2Results = searchBothSources($keywords[1], $conn); displayResults($word2Results, "Related to \"" . htmlspecialchars($keywords[1]) . "\"", $base_url); } echo "</div>"; echo "<hr style='border-top: 1px solid white; margin-top: 20px;'>"; ?>
SIMPAN
BATAL