DJTim666 Posted September 27, 2007 Share Posted September 27, 2007 I am having trouble ordering by ASC. I made a tagbox, and when it loads up it takes you to the bottom of the page, and it should show the newest comment first, but it doesn't. It shows the first 25 tags then stops... mysql_query("SELECT * FROM {table} ORDER BY id ASC LIMIT 25"); Any suggestions? -- DJ Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/ Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 Newest comment first is DESC (Descending) not ASC (Ascending). Rergards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356329 Share on other sites More sharing options...
DJTim666 Posted September 27, 2007 Author Share Posted September 27, 2007 If I order by DESC then will show the newest tag at the top... Is there any way to reverse DESC? Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356331 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 If you're ordering by ID (Assuming that id is auto incrementing) then use DESC Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356333 Share on other sites More sharing options...
DJTim666 Posted September 27, 2007 Author Share Posted September 27, 2007 I can't order by DESC because it will show the newest tag at the top of the page. I want the newest post to be shown at the bottom (like most tagboxes do). Can I use DESC and still be able to show the newest tag at the bottom of the screen? so an example would be; old old old old new Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356334 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 What columns are in your database? Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356335 Share on other sites More sharing options...
DJTim666 Posted September 27, 2007 Author Share Posted September 27, 2007 id, message, username, ip Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356336 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 OK, well the tagbox here shows the newest messages at the top of the box! Which would be "SELECT * FROM table ORDER BY id DESC LIMIT 25". If you wanted it the other way around then you'd need to use this more than one query. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356340 Share on other sites More sharing options...
DJTim666 Posted September 27, 2007 Author Share Posted September 27, 2007 The tagbox here takes you to the bottom of the screen and shows the newest tag at the bottom. nvm, you cant see it unless you are logged in anyways. i'll figure it out someday =). Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356341 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 I can't see that, I guess it's a member only feature. You can do it, but you'd need more than one query, that's all. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356343 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 Something like this should work (Untested)... <?php // Maximum posts to show $show = 25; // Run the query and assign the total rows to a variable $r = mysql_query("SELECT count(`id`) FROM `table`"); $total = mysql_result($r, 0, 0); // Set the true offset if the value is less than 0 $offset = ($total - $show < 0) ? 0 : $total - $show; // Run the query with the offset $r = mysql_query("SELECT * FROM `table` ORDER BY id LIMIT $offset, $show"); // Then process $r as you were before ?> Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356347 Share on other sites More sharing options...
DJTim666 Posted September 27, 2007 Author Share Posted September 27, 2007 That works perfect Huggie. Thank you very much for that. Quote Link to comment https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/#findComment-356539 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.