The idea is to create the following:
$sql = "SELECT column1, column2 FROM table1
UNION SELECT column1, column2 FROM table2
UNION SELECT column1, column2 FROM table3
ORDER BY 'column3'";
I wanna keep it DRY tho, so I came up with the following already thinking about the possible dozens of tables I might use:
$tables = array('table1', 'table2', 'table3');
$array_of_tables = array('SELECT column1, column2 FROM ', $tables[0]);
for($i = 1; $i < count($tables); $i++){
array_push($array_of_tables, "UNION SELECT column1, column2 FROM " . $tables[$i]);
}
array_push($array_of_tables, "ORDER BY 'eng'" . '"');
$sql = implode('', $array_of_tables);
I get the correct string, however I'm not able to use it. Could anyone please tell me what's going on and how to fix it - please, explain in newbie terms! I'm new to PHP and decided to give it a shot, even though half the internet says it's not worthy it. Cheers!