我有一个Windows 7系统与Wamp 2.4运行这个简单的PHP代码
for ($year = 2004; $year <= 2015; $year++){
for ($month = 1; $month <=12; $month++){
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT sum(Weight) FROM Lab WHERE YEAR(date)=$year AND MONTH(date)= $month") or die(mysql_error());
while ($rows = mysql_fetch_array($result)) {
$weight = $rows['sum(Weight)'];
${'mes'.$month}=$weight;
$weight3=$weight+$weight3;
$weight=0;
}
}
Echo $year, " Total - ", $weight3, "<br>";
Echo $mes1, ", ", $mes2, ", ", $mes3, ", ", $mes4, ", ", $mes5, ", ", $mes6, ", ", …Run Code Online (Sandbox Code Playgroud)