<?php
$tables = '';
$daysInMonth = 30; // untrue, just an example..
for($i = 1; $i <= $daysInMonth; $i++)
{
if(strlen($i) < 2) $i = str_pad($i, 2, '0', STR_PAD_LEFT);
if($i===$daysInMonth) $tables .= 'table_' . $i . '_03_13';
else $tables .= 'table_' . $i . '_03_13, ';
}
$query = 'SELECT * FROM ' . $tables;
echo $query;
?>
输出:
SELECT * FROM table_01_03_13, table_02_03_13, table_03_03_13, table_04_03_13, table_05_03_13, table_06_03_13, table_07_03_13, table_08_03_13, table_09_03_13, table_10_03_13, table_11_03_13, table_12_03_13, table_13_03_13, table_14_03_13, table_15_03_13, table_16_03_13, table_17_03_13, table_18_03_13, table_19_03_13, table_20_03_13, table_21_03_13, table_22_03_13, table_23_03_13, table_24_03_13, table_25_03_13, table_26_03_13, table_27_03_13, table_28_03_13, table_29_03_13, table_30_03_13