0
$date['"01.06.2012"'] = '2012-06-01'; 
$date['"01.05.2012"'] = '2012-05-01'; 
$date['"01.04.2012"'] = '2012-04-01';
$date['"01.03.2012"'] = '2012-03-01';
$date['"01.02.2012"'] = '2012-02-01';
$date['"01.01.2012"'] = '2012-01-01';     

foreach($date as $month => $actual_date)
{  /* start foreach loop */
$query = "select Player, SUM(points) AS score from rankings WHERE
`drop_date` > '$actual_date' 
AND `drop_date` <= DATE_ADD('$actual_date',  INTERVAL 1 YEAR) 
GROUP BY Player
ORDER BY SUM(sa_points) LIMIT 0,5";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
echo $row['player'];
echo $row['score']; }

} /* end foreach loop */

现在我只想向这个结果表添加另一个查询,我已经尝试过create temporary table但不知道根据 foreach 循环将它放在哪里,并且不断得到解析错误或最后的$actual_date结果。

4

1 回答 1

2

这是你想要达到的目标吗?

$date['"01.06.2012"'] = '2012-06-01'; 
$date['"01.05.2012"'] = '2012-05-01'; 
$date['"01.04.2012"'] = '2012-04-01';
$date['"01.03.2012"'] = '2012-03-01';
$date['"01.02.2012"'] = '2012-02-01';
$date['"01.01.2012"'] = '2012-01-01';     

mysql_query('CREATE TEMPORARY TABLE results (player varchar(100), score int)');

foreach($date as $month => $actual_date)
{  /* start foreach loop */

    $query = "insert into results (player, score) 
    select Player, SUM(points) AS score from rankings WHERE
    `drop_date` > '$actual_date' 
    AND `drop_date` <= DATE_ADD('$actual_date',  INTERVAL 1 YEAR) 
    GROUP BY Player
    ORDER BY SUM(sa_points) LIMIT 0,5";
    mysql_query($query) or die(mysql_error());
} /* end foreach loop */

$result = mysql_query('select * from results') or die(mysql_error());
while($row = mysql_fetch_array($result)){
    echo $row['player'];
    echo $row['score']; 
}
于 2012-06-25T18:10:57.203 回答