atticus Posted January 9, 2008 Share Posted January 9, 2008 noob question I know ??? How do I order the following search to return only records processed in the last 30 days? <?php echo "<h3>Subjects Searched in Last Thirty Days:</h3><center> <table border=1 style=\"border-collapse:collapse;\"> <tr> <th style=\"padding-right:5px;\">Last Name, First Name</th> <th style=\"padding-right:5px;text-align:center;\">Processed (yyyy - mo - dy)</th> </tr> "; $sql = "SELECT * FROM `order` WHERE cust_id = $id AND processed = 'yes' ORDER BY processeddate DESC, last_name ASC"; $query = mysql_query($sql) or die('Error, query failed : ' . mysql_error()); while($row = mysql_fetch_array($query)) { echo "<tr> <td>".$row['last_name'].", ".$row['first_name']."</td> "; echo "<td style=\"text-align:center;\">".$row['processeddate']."</td> </tr>"; } echo "</table></center>"; ?> Link to comment https://forums.phpfreaks.com/topic/85254-solved-mysql-ordering-by-last-30-days/ Share on other sites More sharing options...
pocobueno1388 Posted January 9, 2008 Share Posted January 9, 2008 Try SELECT * FROM `order` WHERE cust_id = '$id' AND processed = 'yes' AND processeddate < (NOW() - INTERVAL 30 DAY) ORDER BY processeddate DESC, last_name ASC Link to comment https://forums.phpfreaks.com/topic/85254-solved-mysql-ordering-by-last-30-days/#findComment-434914 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Depends on how you store your date format. Link to comment https://forums.phpfreaks.com/topic/85254-solved-mysql-ordering-by-last-30-days/#findComment-434917 Share on other sites More sharing options...
rhodesa Posted January 9, 2008 Share Posted January 9, 2008 For future reference, check out http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html The first example on the page shows how to get records from the past 30 days. Link to comment https://forums.phpfreaks.com/topic/85254-solved-mysql-ordering-by-last-30-days/#findComment-434919 Share on other sites More sharing options...
atticus Posted January 9, 2008 Author Share Posted January 9, 2008 thanks everybody and I appreciate the link... $sql = "SELECT * FROM `order` WHERE cust_id = $id AND processed = 'yes' AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= processeddate ORDER BY processeddate DESC, last_name ASC"; Link to comment https://forums.phpfreaks.com/topic/85254-solved-mysql-ordering-by-last-30-days/#findComment-434922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.