Skip to content

Commit 45019b3

Browse files
authored
Update README.md
1 parent 4cabb13 commit 45019b3

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# PHPSearchController
22

3-
PHPSearchController is a simple php class to search mysql database,
3+
PHPSearchController is a simple php class to search mysql database, it can build SQL query to perform MySQL database searches by takeing parameters that define database table fields and field values to search.
4+
5+
The class generates SQL conditions used to build SQL queries to perform database searches for records that match the criteria based on the table fields and field values defined by the parameters, It then combine several conditions using SQL operators such as `AND, OR, NAND, LIKE NOR & FIND_IN_SET` and return the appropriate queries for the search.
46

57
## Installation
68

@@ -9,31 +11,41 @@ Installation is super-easy via Composer:
911
composer require peterujah/php-search-controller
1012
```
1113

14+
# Usages
15+
16+
Initialize the class with your preferred search method the default method is `SearchController::OR`.
1217
```php
1318
use Peterujah\NanoBlock\SearchController;
14-
$search = new SearchController(SearchController::OR);
19+
$search = new SearchController();
20+
```
21+
22+
23+
Set your preferred search operator the default is `SearchController::END_WITH_QUERY`.
24+
```php
1525
$search->setOperators(SearchController::HAVE_ANY_QUERY);
1626
```
1727

18-
# Usages
28+
To perform a database search build the search query like below.
1929

2030
```php
2131
$searchQuery = "PHP Code";
22-
$searchByTags = false;
23-
2432
$search->setQuery($searchQuery)->split();
33+
$search->setParameter(array(
34+
'code_title',
35+
'code_description',
36+
'code_info'
37+
));
38+
//var_export($search->getQuery());
39+
```
2540

26-
if(!$searchByTags){
27-
$search->setParameter(array(
28-
'code_title',
29-
'code_description',
30-
'code_info'
31-
));
32-
}else{
33-
$search->setTags("code_tags");
34-
}
41+
To search by tag using mysql `FIND_IN_SET`, build query like example below.
42+
```php
43+
$searchQuery = "PHP Code";
44+
$search->setQuery($searchQuery)->split();
45+
$search->setTags("code_tags");
3546
//var_export($search->getQuery());
3647
```
48+
3749
Set inital query and pass search query to your mysql connection
3850

3951
```php

0 commit comments

Comments
 (0)