Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EbrahemSamer's avatar

How to search in two table Dynamically PHP ?

I've two tables .. say users table and books table I wanna make search in both but I wanna write the code once dynamically . understand which table should look in and what fields should use to search.

Any Ideas ?

0 likes
5 replies
EbrahemSamer's avatar

@sinnbeck Pure PHP, I want an idea..

also two tables have different fields.... and different rules for search

Sinnbeck's avatar

Well if it is just the logic, you could perhaps make each param start with the table name and then extract it from the string

http://website.com? table1_name=john&table2_age=44&table2_position=manager

foreach ($requestparameters as $key =>$param) {
    $arr= implode('_', $key);
    $search[$arr[0]][$arr[1]] = $param;
}

Please or to participate in this conversation.