I have the following line:
$products = $dbh->query("SELECT piP2Components.typeID, invTypes.typeName FROM piP2Components INNER JOIN invTypes ON piP2Components.typeID = invTypes.typeID ORDER BY invTypes.typeName ASC;");
I have another table, piP3Components and I would like to run the same query on it and have the results added to the $products variable. As the result is a PDOStatement object I can’t simply array_push.
How would I go about doing this? Alternatively, I’m fairly new to using JOIN queries, is there a way to accomplish this in SQL without having the piP3Components.typeID results in a different column?
Thanks.
You have two options.
First, if the columns you’re picking from each table have identical column types, you can use a
UNION:Second, you can run both queries, then fetch the results for each and place them in a single array, using that array later instead of the statement handle when processing the results: