我有一个名为“main_table”的表,包含 3 列:
“player”、“points”和“drop_date”
我有 1 个具有不同值的变量 ($date):
$date == '2012-06-01'
$date == '2012-05-01'
$date == '2012-04-01'
我有 1 个 MySQL 查询:
$query = "
select *
from main_table
where `drop_date` > '$date'
AND `drop_date` <= DATE_ADD('$date', INTERVAL 1 YEAR)
LIMIT 1
";
目标:
我想用不同的pass运行一个查询(每个值1pass)
我努力了 :
<?php
$date['date'] = '2012-06-01';
$date['date'] = '2012-05-01';
$date['date'] = '2012-04-01';
foreach($date as $title => $actual_date) {
query = "
select *
from main_table
where `drop_date` > '$actual_date'
AND `drop_date` <= DATE_ADD('$actual_date', INTERVAL 1 YEAR)
LIMIT 1
";
$result = mysql_query($query) or die(mysql_error());
}
while($row = mysql_fetch_array($result)) {
echo $row['Player'];
echo $row['Points'];
}