SELECT * FROM (SELECT table_name FROM orders WHERE id_client=3 and id_agent=1) WHERE id_product=$idp There selects the name of the table, and from it displays information
In orders there is a list of tables, so I substitute them. and from each table I take data.
"SELECT table_name FROM orders WHERE id_client=3 and id_agent=1 and id_product=" .$idp. You need to expand this query into two. In oracle there is a dynamic sql for this, in mysql as far as I know not - cadmy