des1017 Posted July 26, 2008 Share Posted July 26, 2008 I've tried to find some information on this, but didn't have any luck. I've got roughly 7 columns in one of my tables (date being one of them ie 20080725) I want to display a while statement for instance like this: $queryx = "SELECT * FROM $tableunits"; $resultx = mysql_query($queryx); $counter = 1; while($row = mysql_fetch_array($resultx, MYSQL_BOTH)) { if($counter <= 10) { echo "<div id='nitem'> <a href='jewelry.php?item=".$row["unitid"]."'><img src='jewelry/".$row["unitimage"]."' alt='".$row["unitname"]."' width='100' height='100'><br />-> Click Here</a> </div>"; } $counter = $counter + 1; } except I want to display the first 10 sorted by the most recent date added, which happens to be the date column in my table. Link to comment https://forums.phpfreaks.com/topic/116672-solved-outputting-sql-rows-by-a-specific-column/ Share on other sites More sharing options...
sader Posted July 26, 2008 Share Posted July 26, 2008 $queryx = "SELECT * FROM $tableunits ORDER BY date DESC LIMIT 10"; Link to comment https://forums.phpfreaks.com/topic/116672-solved-outputting-sql-rows-by-a-specific-column/#findComment-599880 Share on other sites More sharing options...
des1017 Posted July 26, 2008 Author Share Posted July 26, 2008 I see, so that saves me an IF function too then? what about outputting alphabetically? Link to comment https://forums.phpfreaks.com/topic/116672-solved-outputting-sql-rows-by-a-specific-column/#findComment-599881 Share on other sites More sharing options...
awpti Posted July 26, 2008 Share Posted July 26, 2008 Just sort by the field. Link to comment https://forums.phpfreaks.com/topic/116672-solved-outputting-sql-rows-by-a-specific-column/#findComment-599886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.