I'm trying to fetch an array from a MySQL database but I can't when using a php variable ($final_date) instead of a string (2015-02-16). Can anyone help me?
Here is the code:
$date = new DateTime(date("Y-m-d"));
$date->modify('-1 day');
$prev_date = $date->format('Y-m-d');
$final_date = (string)$prev_date;
function GetPrevUsers(){
$Adname = "Error";
$query = mysql_query("SELECT users FROM stats WHERE date = '".$final_date."'");
while($row = mysql_fetch_array($query)){
$Adname = $row['users'];
}
return $Adname ;
}
echo GetPrevUsers();
For some reason it the function works when I use the actual date instead of the php variable like this:
$query = mysql_query("SELECT users FROM stats WHERE date = '2015-02-16'");
$final_dateas a parameter with youGetPrevUsers()function.