Creating a PHP script to search through a MySQL database and display the results, is a fairly simple task. Using the MySQL LIKE and NOT LIKE operands, we can find specific values within our database tables.
MySQL gives us the ability to search for terms exactly as they are entered or close to what is entered by using the percentage % or the underscore _ character.
The underscore character _ tells MySQL to look for one additional character for each underscore.
The percentage character % tells MySQL to look for zero or more additional characters. Only one percent character is used, and can be used at the start and end of a searched term.
Take a look at this example:
$sql = mysql_query(“SELECT * FROM table_name WHERE columnname LIKE value%“);
while ($row = mysql_fetch_row($sql)) {
echo “$row[0] $row[1] $row[2] <br />”;
}
This example will return all results where value is found in the database table. This would include terms like value-added, valued, values, etc. Get the idea?
Feel free to comment or ask questions.