The PHP statement is used to query multiple tables in MYSQL and displayed on the page. the fields of multiple tables are the same and the table names are different. For example: & nbsp; abc201202, abc201203, abc201204... the table name is created on a monthly basis. I am new users don't know how to traverse multiple tables at a time to extract MYSQL data ., The PHP statement is used to query multiple tables in MYSQL and displayed on the page.
The PHP statement is used to query multiple tables with the same fields and different table names. For example:
Abc201202, abc201203, abc201204... table name created on a monthly basis
I don't know how to traverse multiple tables at a time to extract data from MYSQL.
------ Solution --------------------
PHP code
$ Table = array ("abc201202", "abc201203", "abc201204"); $ result = array (); foreach ($ table as $ table_name) {$ SQL = "select * from ". $ table_name; $ rec = mysql_query ($ SQL); while ($ row = mysql_fetch_row ($ rec) {$ result [] = $ row ;}}
------ Solution --------------------
PHP code
$ Select = array (); $ table = array ("abc201202", "abc201203", "abc201204"); foreach ($ table as $ v) {$ select [] = "(select * from $ v)";} $ SQL = join ('join', $ select); $ res = mysql_query ($ SQL );
------ Solution --------------------
PHP code
$ Table = array ("abc201202", "abc201203", "abc201204"); $ result = array (); $ count = count ($ table)-1; // subtract an array subscript for ($ I = 0; $ I <$ count; $ I ++) {$ SQL = $ SQL. "select * from '". $ table [$ I]. "'union all";} $ SQL = $ SQL. "select * from '". $ table [$ count]. "'"; $ rec = mysql_query ($ SQL); while ($ row = mysql_fetch_row ($ rec) {$ result [] = $ row ;}