How to Concatenate table name with with a variable value in mySQL

Viewed 1646

I'm trying to create a dynamic code that would ready from any table with the certain name but the difference between each table name is a number that is generated by a variable: for example :

//that's how I get my variable the value for example is = 3

$pid = $GLOBALS["localid"];

//the table name for example is tablename_3

$strTable = "tablename_" .$pid;

//here's how the query should look like

$query = "SELECT * FROM . $strTable . where .....;

I'm making a mistake somewhere but can't figure it out and would appreciate a little help please

2 Answers
Related