I have a table called ‘main_table’ with 3 columns :
‘player’, ‘points’ and ‘drop_date’
I have 1 variable ($date) with different values:
$date == '2012-06-01'
$date == '2012-05-01'
$date == '2012-04-01'
I Have 1 MySQL query:
$query = "
select *
from main_table
where `drop_date` > '$date'
AND `drop_date` <= DATE_ADD('$date', INTERVAL 1 YEAR)
LIMIT 1
";
GOAL :
I would like to run ONE query with different passes (1pass per value)
I have tried :
<?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'];
}
Just move your while in the foreach loop.