Process data differently for each table in a database

I have a query that goes something like this:


$result = $con->query("SELECT * FROM table1, table2, table3 WHERE type = 3 OR type = 4 ORDER BY added DESC");

I want to create objects from the query result. So, it’ll be something like this:


$i = 0;
while($row = result->fetch_assoc()) {
$object_name[$i] = new object1();
$i;
}

However, I want different object types to be created for each table. So, if the result was taken from table1, I want to generate an ‘object1’, if it’s from table2 I want to generate an ‘object2’, etc.

Essentially, each table in my DB corresponds to an object type, and whilst I want to query them all together, I want to actually form the object correctly based on the table it was from.

I hope that makes sense and someone can point me in the right direction with this :slight_smile: