jonaHill87 Posted July 16, 2008 Share Posted July 16, 2008 Hey all. I'm trying to loop through an array backwards but can't get it right. I'm getting my data through mysql_fetch_row and using mysql_num_rows to get the number of rows. I know how to loop forward through my fields but not backwards. Here's my foward loop for my first field. I'd like to loop this feild backwards. I'm guessing I need to use a for loop as well but I can't figure it out. $query = "SELECT * FROM Table"; $result = mysql_query($query); $num = mysql_num_rows($result); while ($data = mysql_fetch_row($result)) { echo $data[0]; } Link to comment https://forums.phpfreaks.com/topic/114956-solved-loop-through-array-backwards/ Share on other sites More sharing options...
xtopolis Posted July 16, 2008 Share Posted July 16, 2008 Use mysql to order by a certain column, then set the method to descending. "SELECT * FROM Table ORDER BY somecolumn DESC"; Link to comment https://forums.phpfreaks.com/topic/114956-solved-loop-through-array-backwards/#findComment-591235 Share on other sites More sharing options...
BillyBoB Posted July 16, 2008 Share Posted July 16, 2008 This one is easy just put a desc value in your query. I'm pretty sure that it will just order the table backwards <?php $query = "SELECT * FROM Table ORDER BY row DESC"; $result = mysql_query($query); $num = mysql_num_rows($result); while ($data = mysql_fetch_row($result)) { echo $data[0]; } ?> Link to comment https://forums.phpfreaks.com/topic/114956-solved-loop-through-array-backwards/#findComment-591236 Share on other sites More sharing options...
jonaHill87 Posted July 17, 2008 Author Share Posted July 17, 2008 Ah yes. Sort by descending order. Thanks. Link to comment https://forums.phpfreaks.com/topic/114956-solved-loop-through-array-backwards/#findComment-592157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.