<?php
// config
$table_name = "calendar_event"; //which table from database
$first_field = "event"; //which field from table
$second_field = "company"; //which field from table
$third_field = "description";
$fourth_field = "city";
$limitchar = 3; //minimum of characters
$records_number = 100; // Number of records to show per page (different from 0)
$page_number = 1;// default start page
$offset = 0;
$arraySearch = array('inv', 'test');
// Generate query
$arrayFields = array(0 => $first_field, 1 => $second_field, 2 => $third_field, 3 => $fourth_field);
$countSearch = count($arraySearch);
$a = 0;
$b = 0;
$query = "SELECT * FROM `$table_name` WHERE (";
$countFields = count($arrayFields);
while ($a < $countFields)
{
while ($b < $countSearch)
{
$query = $query."`$arrayFields[$a]` LIKE '%$arraySearch[$b]%'";
$b++;
if ($b < $countSearch)
{
$query = $query." AND ";
}
}
$b = 0;
$a++;
if ($a < $countFields)
{
$query = $query.") OR (";
}
}
$query = $query.") LIMIT $offset, $records_number;";
var_dump($query);