I need to search for data in different tables which are stored in an array, how can I make the query?
I have an array tables_array in which I have different table names I need to search for data with some 'where' conditions within these tables
If you want to search to all tables do
$sql = "";
$table_array=array('table_name_1', 'table_name_2', 'table_name_3');
foreach($table_array as $v) {
if($sql !== "") {
$sql .= " union";
}
$sql .= "select * from `$v` where `field_search` = '$search_value'";
}
echo $sql; //test your sql
I think you need to join these three tables for one query.
For example :
select * from table1 t1
join table2 t2 on t2.field='%search%'
join table3 t3 on t3.field='%search%'
where t1.field='%search%'