Jump to content

print dates in descending order without affecting the query


php_begins

Recommended Posts

i am printing the dates from the last 30 days in ascending order and then comparing them in my query to print the results. How can I can print the below array in descending order without affecting my query?

   
  $thirtydaysago = time() - (30 * 24 * 60 * 60);
  
  $oneday=24 * 60 * 60;
  for($i=0;$i<31;$i++)
  {
     $d[$i]= $thirtydaysago + ($i*$oneday);
 echo date('Y-m-d',$d[$i])."<br>";
  }
  for($i=0;$i<31;$i++)
  {
     $postsql=mysql_query("SELECT DATE_FORMAT(FROM_UNIXTIME(dateline), '%Y-%m-%d') AS FmtDate, COUNT(postid) AS PostCnt FROM post " . 
              "WHERE dateline < '" . $d[$i+1] . "' AND dateline >= '" . $d[$i] . "' GROUP BY DATE_FORMAT(FROM_UNIXTIME(dateline), '%Y-%m-%d') DESC") or die(mysql_error());
   

   if($postsql_rows=mysql_fetch_assoc($postsql))
   {
    $data_date[$i]["date"]=$postsql_rows['FmtDate'];
$data_postcount[$k][$i]["postcount"]=$postsql_rows['PostCnt'];
   }
}
$k++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.