Hello I am developing an ajax php search. It will search through the database accross multiple tables when someone types. My question is that i need it to bring up a name like if someone types the name Apple tv i want it to bring up do you want the category or the specific product?. How can i do that?
This is what I have so far:
<?php
//Database values
$host = "localhost";
$dbname = "tool";
$user = "root";
$password = "root";
$database = new mysqli();
$database->connect($host, $user, $password, $dbname);
//Kill website if database connection fails
if($database->connect_errno) {
die("Database connection failed.");
}
//Connect to the database
//Clean user input
$search = $database->real_escape_string($_POST['search']);
$search = preg_replace("/[^A-Za-z0-9 ]/", '', $search);
$search = "'%".$_POST['search']."%'";
$query = "SELECT * FROM brands WHERE braname LIKE $search ORDER by braname ASC LIMIT 5";
if($results = $database->query($query)){
while ($player = $results->fetch_assoc()){
echo "<div class='col-sm-4' id='adjust-Searchbox'>" . "<a href=\"users/e-commerceTemplateSingleBrand.php?braid=".$player['braid']."\">" . "<p>" . $player["braname"] . "</p>" . "<img style='width:100%; height:50px;' src=\" uploads/".$player['braimg']."\">" . "</a>" . "</div>"
;
}
}else{
die("Database connection failed.");
}
$search = $database->real_escape_string($_POST['search']);
$search = preg_replace("/[^A-Za-z0-9 ]/", '', $search);
$search = "'%".$_POST['search']."%'";
$query = "SELECT * FROM Products WHERE name LIKE $search ORDER by name ASC LIMIT 5";
if($results = $database->query($query)){
while ($player = $results->fetch_assoc()){
echo "<div class='col-sm-4' id='adjust-Searchbox'>" . "<p>" . $player["name"] . "</p>" . "<img style='width:100%; height:50px;' src=\" uploads/".$player['proimg']."\">" . "</br>" . "</div>";
}
}else{
die("Database connection failed.");
}