I have a situation where I am able to choose from multiple tables in a MYSQL database. At any given time I only need to access one table.
Can I put the name of the table inside a variable and then set that within the query? Such that when I want to change the table, I only need to update a variable?
I am thinking kind of like this:
Instead of:
$order = "SELECT * FROM 2FieldForm ORDER BY ID";
do this:
$table = mysql_select_table("2FieldForm");
$order = "SELECT * FROM $table ORDER BY ID";
Now I am not sure if mysql_select_table is even valid, but I hope it gets the idea across!
Thanks in advance!
The SQL is simply a string, so have the table name inside a variable and execute the query using
mysql_query()Be sure to add quotes to your table name and field in order to make sure it’s properly interpreted by the database. The semi-colon at the end isn’t necessary, but helps.