Reputation: 11
I have a search engine based on multiple select options that the user can enter a lot of option and the search engine fetch the database to get the the results of arrays that entered in the the select options but I need to make this code to fetch and get ordered the results by the most relevant so this is the code :
<?php
//doctors.php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
$query = "SELECT DISTINCT Symptome4 FROM tbl_customer ORDER BY Symptome4 ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
?>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Home Page</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" />
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
<link rel="stylesheet" href="./css/style.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href=".\css\bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap-select.min.css" rel="stylesheet" />
<script src="js/bootstrap-select.min.js"></script>
</head>
<body>
<main class="find-bar">
<header id="header">
<div class="overlay overlay-lg">
</div>
<nav>
<div class="container">
<div class="logo">
<h1>Oxygenta</h1>
</div>
<div class="links">
<ul>
<li>
<a href="file:///C:/Users/yosse/OneDrive/Desktop/AAST/Year%204/Semester%208/Graduation%202/Oxygenta/homepage2/index2.html">Home</a>
</li>
<li>
<a href="#">Diagnosis</a>
</li>
<li>
<a href="file:///C:/Users/yosse/OneDrive/Desktop/AAST/Year%204/Semester%208/Graduation%202/Oxygenta/3in1/doctors.html">Doctors</a>
</li>
<li>
<a href=" file:///C:/Users/yosse/OneDrive/Desktop/AAST/Year%204/Semester%208/Graduation%202/Oxygenta/3in1/find-doctors.html">Home Doctors</a>
</li>
<li>
<a href=" file:///C:/Users/yosse/OneDrive/Desktop/AAST/Year%204/Semester%208/Graduation%202/Oxygenta/3in1/find-nurse.html">Nurses</a>
</li>
<li>
<a href="file:///C:/Users/yosse/OneDrive/Desktop/AAST/Year%204/Semester%208/Graduation%202/Oxygenta/Ticket/ticket.html">Help</a>
</li>
<li>
<a href="file:///C:/Users/yosse/OneDrive/Desktop/AAST/Year%204/Semester%208/Graduation%202/Oxygenta/login.html" class="active">Sign Out</a>
</li>
</ul>
</div>
</nav>
<div class="header-content">
<div class="container content">
<div class="column-1">
<h1 class="header-title">Find Your <br /> Favorite Doctor</h1>
<div class="wrapper">
<div class="search_box">
<div class="search_btn"><i class="fas fa-search"></i></div>
<input type="text" class="input_search" placeholder="What are you looking for?">
</div>
</div>
</div>
<img src="./img/doctor_PNG16022.png" class="img-bar" alt="" />
</div>
</div>
</header>
<section class="services section">
<div class="container left">
<div class="section-header">
<h2 data-title="">Symptoms</h2>
</div>
</div>
</section>
<div class="container">
<select name="multi_search_filter" id="multi_search_filter" multiple class="form-control selectpicker" style="width: 50%;">
<option value="Runny Nose">Runny Nose</option>
<option value="Sore Throat">Sore Throat</option>
<option value="Headaches">Headaches</option>
<option value="Sneezing">Sneezing</option>
<option value="High Temperature">High Temperature</option>
<option value="Hoarse Voice">Hoarse Voice</option>
<option value="Difficulty Swallowing">Difficulty Swallowing</option>
<option value="Drooling">Drooling</option>
<option value="Weak Voice">Weak Voice</option>
<option value="Coughs">Coughs</option>
<option value="Dry Throat">Dry Throat</option>
<option value="Difficulty Speaking">Difficulty Speaking</option>
<option value="Throat Pain">Throat Pain</option>
<option value="Fever">Fever</option>
<option value="Difficulty Breathing">Difficulty Breathing</option>
<option value="Loss Of Smell">Loss Of Smell</option>
<option value="Loss Of Taste">Loss Of Taste</option>
</select>
<input type="hidden" name="hidden_country" id="hidden_country" />
<br />
<table class="table table-striped ">
<tbody>
</tbody>
</table>
</section>
<script>
$(document).ready(function(){
load_data();
function load_data(query='')
{
$.ajax({
url:"fetch.php",
method:"POST",
data:{query:query},
success:function(data)
{
$('tbody').html(data);
}
})
}
$('#multi_search_filter').change(function(){
$('#hidden_country').val($('#multi_search_filter').val());
var query = $('#hidden_country').val();
load_data(query);
});
});
</script>
and this for fetch.php
<?php
//fetch.php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
if($_POST["query"] != '')
{
$search_array = explode(",", $_POST["query"]);
$search_text = "'" . implode("', '", $search_array) . "'";
$query = "
SELECT * FROM tbl_customer
WHERE Symptome4 IN (".$search_text.") OR Symptome2 IN (".$search_text.") OR Symptome1 IN (".$search_text.") OR Symptome3 IN (".$search_text.") OR Symptome5 IN (".$search_text.")
ORDER BY DiseaseID DESC ";
}
else
{
$query = "SELECT * FROM tbl_customer ORDER BY DiseaseID DESC";
}
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '';
if($total_row > 0)
{
foreach($result as $row)
{
$output .= '
<table><tr><td>
<div class="cards"></td>
<td><div class="card-wrap">
<div class="card ">
<div class="card-content z-index">
<img src="./img/nurse.png" class="icon" alt="" />
<h3 class="title-sm">'.$row["DiseaseName"].'</h3>
<h5 style="text-align: left;">
'.$row["Symptome1"].'
</p>
<p>
'.$row["Symptome2"].'
</p>
<p>
'.$row["Symptome3"].'
</p>
<p >
'.$row["Symptome4"].'
</p>
<p >
'.$row["Symptome5"].'
</p>
<a href="file:///C:/Users/yosse/OneDrive/Desktop/AAST/Year%204/Semester%208/Graduation%202/Oxygenta/3in1/find-nurse.html" class="btn small">More Info</a>
</td>
<td>
</div>
</div>
</div>
</div>
</div>
';
}
}
else
{
$output .= '
<tr>
<td colspan="5" align="center">No Data Found</td>
</tr>
';
}
echo $output;
?>
and this is the result: enter image description here
Upvotes: 1
Views: 45