I am writing a php search function that allows users to specify search parameters (using a regular html form) and then displays the results that match the user's parameters.
I have two tables in my mysql database, and I want the user to be able to specify whether to search in the first table, the second table or both.
My problem is, how do I tell mysql which table the user has specified? At first I tried to pass the name of the table from the form into a php variable and then use that variable in my mysql query, like so:
$result = mysql_query('SELECT * FROM $tableName');
But of course this doesn't work.
Can anyone suggest a way to pass my php variable to mysql so that it knows what I'm talking about? Or possibly (this is no doubt more likely) a better, not stupid way of doing what I'm trying to do?
Any help is highly appreciated!