I am new to php and mysql programing and I have a question in working with the date.
There is a date field that stores the date in the table
eg 2013-05-27, 2013-05-24, 2013-05-22
I need to retrieve the latest 3 days data for further processing, first is locate today's date, if cannot find, then will locate yesterday's data, if cannot find, then locate the date before yesterday's data etc. Then I have the below code:
$date1=date('Y-m-d');
$date1_1="";
$datefound="";
while( $datefound <> ""){
$date1_1_1 = mysql_query("SELECT * FROM jom_c1 where date ='" .$date1. "'");
if($date1_1_1){
$datefound = $date1;
}else{
$date1 = date('Y-m-d', strtotime($date . ' - 1 day'));
}
}
echo $datefound;
?>
however, it seems like the loop is not running, much appreciated if someone can give me a hints with it.