php_begins Posted September 9, 2011 Share Posted September 9, 2011 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/246786-print-dates-in-descending-order-without-affecting-the-query/ Share on other sites More sharing options...
jamesxg1 Posted September 9, 2011 Share Posted September 9, 2011 Maybe something simple might do the trick. for($i = 0; $i < count($ARRAY_VAR_HERE); $i++) { echo $ARRAY_VAR_HERE[(count($ARRAY_VAR_HERE) - $i)]; } James. Quote Link to comment https://forums.phpfreaks.com/topic/246786-print-dates-in-descending-order-without-affecting-the-query/#findComment-1267364 Share on other sites More sharing options...
php_begins Posted September 9, 2011 Author Share Posted September 9, 2011 But I am also comparing it with the dateline in the query above..so its not working correctly.. Quote Link to comment https://forums.phpfreaks.com/topic/246786-print-dates-in-descending-order-without-affecting-the-query/#findComment-1267379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.