I have a simple search box on my website which for now only produces results based on certain criteria being met.
if(isset($_GET['action'])&&isset($_GET['searchbox'])) {
if($_GET['searchbox']!='') {
$result = mysql_query("SELECT * FROM `restaurants` WHERE `restaurant` LIKE '%{$_GET['searchbox']}%'"); // RESULT IS FIND EVERYTHING THAT MATCHES SEARCH FROM TABLE //
} else {
$result = mysql_query("SELECT * FROM `restaurants`");
}
}
<form action="search.php" id="searchform" method="get" class="searchbox-container">
<input type="text" id="searchbox" name="searchbox" class="searchbox" />
<input type="submit" class="searchbox-btn" value="Search" />
<input type="hidden" name="action" value="search" />
What i want is for the search box to return a result from the database from all table data not just specific data such as restaurant names.
I also want it to work so that if someone searches for "sto" then results such as "stoke" will show up, so the search doesnt have to be exactly what is in the database.
excuse the code if it is wrong or out of date, this was taken from a university tutorial which is a little old.
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.full text search.