General discussions related to php
Moderators: macek, egami, gesf
- New php-forum User
- Posts: 86
- Joined: Mon Jun 04, 2012 10:05 pm
- Location: Ankara, Turkey
Yes, it is possible to have an Advanced Search which allows users to fill in one or more fields. Solutions usually involve a series of conditionals which build an SQL statement based on the information submitted by the user.
Assuming you are using MySQL, such a solution might look like this:
Code: Select all
$where = array();
$where = sprintf("`name` LIKE '%%%s%%'",
$where = sprintf("`description` LIKE '%%%s%%'",
// Repeat for all other fields...
$sql = "SELECT * FROM `table` WHERE " . implode(' OR ',$where) . ";";
As far as efficiency, it depends on how your application is setup. Optimizing the query in PHP before sending it to an SQL database could improve the performance of your application. However, if you are using an existing Stored Procedure in an SQL database to perform the search, it may save you time to optimize the Stored Procedure, rather than mess with PHP.
I hope that helps. Good luck!
Who is online
Users browsing this forum: No registered users and 1 guest