Well, after having one last ditch attempt, I now have it working! I revisited the earlier solution (the same as the one you posted Dave), as I was starting to wonder if I had gone to far down the rabbit hole!
So, this is the OLD BROKEN code:
<?php $firstTable = true;?>
<?php foreach (getSchemaTables() as $tableName) :?>
<?php if(strpos($tableName, "_main")): ?>
<?php $schema = loadSchema($tableName); ?>
<?php if(@$schema['bike_stock']): ?>
<?php if($firstTable) {
$firstTable = false;
}
else {
echo "UNION";
}
?>
SELECT @i:=@i+1 AS "Column Number", myquery.* FROM (
SELECT `subdomain_name` as "Subdomains List", `dealer_title` as "Dealer Title" FROM `<?php echo $TABLE_PREFIX;?><?php echo $tableName;?>`
WHERE bike_stock = '1'
) myquery, (SELECT @i:=0) myrowcounter
<?php endif; ?>
<?php endif ?>
<?php endforeach ?>
and here is the CURRENT FIXED Code:
<?php $firstTable = true;?>
<?php foreach (getSchemaTables() as $tableName) :?>
<?php if(strpos($tableName, "_main")): ?>
<?php $schema = loadSchema($tableName); ?>
<?php if(@$schema['bike_stock']): ?>
<?php if($firstTable) {
$firstTable = false;
}
else {
echo "UNION";
}
?>
SELECT @i:=@i+1 AS "Column Number", myquery.* FROM (
SELECT `subdomain_name` as "Subdomains List", `dealer_title` as "Dealer Title" FROM `<?php echo $TABLE_PREFIX;?><?php echo $tableName;?>`
WHERE bike_stock = '1'
) myquery, (SELECT @i:=0) myrowcounter
<?php endif; ?>
<?php endif ?>
<?php endforeach ?>
So, the only difference is the new empty line before the first SELECT. That's it. Can someone explain this please? So much time wasted because of a missing empty line. I kind of feel robbed but glad it's fixed.
Thought I would share just in case someone else falls foul of this.