Hi,
If the selection of the table is based on some pattern matching the you will have to first query “show tables”, this will fetch all the table names in an array on which you can run a pattern match. This will give you the name of the table and you can construct a query using the name of the table and user input, execute it and you will get the result.
Here I have assumed that you are working with MySQL and if its some other DBMS then the above query might get changed.
Hope this helps.
Cheers,
~Maneet