I'm trying to make some PHP that creates a query based on what it gets from the URL. I'm pretty sure I'm close to the code required to finish it but I can't get my syntax right. The idea is, it loops through all the companies in the URL ?companies=bla,bla,bla (which I stored in an array) and then for each one it echos part of the SQL statement for $query. I know my code is going to be bad. I am totally aware of that but I can't debug it without the right syntax. If someone could correct my syntax I'd highly appreciate it!
Thanks
$companies = $_GET['companies'];
$companiesArray = explode(',', $companies);
$companiesArrayLength = count($companiesArray);
$query = $db->query(
for ($i = 0; $i < $companiesArrayLength; $i++) {
echo "SELECT * FROM " . $companiesArray[$i] . " UNION ALL";
}
//echo " ORDER BY timestamp DESC LIMIT 50";
);