Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/70887-solved-ordering-by-asc/
Share on other sites

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.