PHP statements query multiple tables in MySQL and display them on the page
The fields that query multiple table tables with the PHP statement are the same, and the table names are different. For example:
abc201202,abc201203,abc201204 ... Table name by Month table
I don't know how to walk through more than one table at a time to extract data from MySQL.
------to solve the idea----------------------
$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;
}
}
------to solve the idea----------------------
$select = Array ();
$table = Array ("abc201202", "abc201203", "abc201204");
foreach ($table as $v) {
$select [] = "(SELECT * from $v)";
}
$sql = Join (' UNION ', $select);
$res = mysql_query ($sql);
------to solve the idea----------------------
$table = Array ("abc201202", "abc201203", "abc201204");
$result =array ();
$count = count ($table) -1;//minus 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;
}