ryanwood4 Posted November 24, 2009 Share Posted November 24, 2009 Hi, Im trying to order results by the amount of reads they have received, but the results cannot be any older than 3 days, unless here isn't any to choose from in that date range, therefore it uses older results. For example: There are 4 items in the table: Item 1 | 59 reads | 24/11/2009 Item 2 | 22 reads | 23/11/2009 Item 3 | 63 reads | 23/11/2009 Item 4 | 99 reads | 18/11/2009 I want it to display Item 3, Item 1 and then Item 2. However say Item 1 wasn't there, then, because there are only 2 items within a 3 day period it uses the next most recent item. I have the simple structure but can't think how to do the above: <?php $con = mysql_connect("localhost","xxxx","xxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxx", $con); $result = mysql_query("SELECT * FROM members ORDER BY reads ASC limit 3"); echo "<table border='0' width='100%'>"; while($row = mysql_fetch_array($result)) { echo '<tr><td><img class="scaled" src="'.$row['image'].'"/></td>'; echo '<td><h6><a href="community/display/'.$row['id'].'">'.$row['title'].'</a></h6>'; echo '<p>Reads: '.$row['reads'].'</p></td></tr>'; } mysql_close($con); ?> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/182787-ordering-results-by-two-values-date-and-reads-how/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.