I have a function that accepts an array of tables as the parameter and after inner joining them returns the resulted rows.
function myfunc($tables, $join_on) {
foreach($tables as $table) {
// build query
}
}
How do I build the query? for example if $tables = array('table1', 'table2') and $join_on = 'field_x' then it should create the following query:
SELECT * FROM table1 INNER JOIN table2 ON table1.field_x = table2.field_x
You can do something like this :
Of course you need to add some error checking to ensure that you have at least one table in
$tablesand always N-1 elements in$join_onwhere N is the number of tables in$tables