Jump to content

Archived

This topic is now archived and is closed to further replies.

Genesis

Concatenating Integers with MySQL, or "get last 10 entr

Recommended Posts

Hi there,

 

For my website I have a news system that will have thousands of entries. What I would like to do is retrieve the 10 most recent entries.

 

Is there a \"get X most recent entries based on index\" function? I do NOT know how to use indexes, or autoincrements or anything like that. I have tried and tried to understand them, but no tutorial I\'ve seen yet has explained them in such a way that I can understand.

 

Or, back to my first question: is there a way to concatenate two integers? I do NOT want them added.. just appending one onto the other, like a string. (I know about the concat() function, but I dunno if it works with integers..)

 

The reason I need to do this is because if I cannot figure out indexes, I will have to concatenate the date with the time and use that as one big number to determine which 10 posts were made most recently.

 

Any help is greatly appreciated :)

Share this post


Link to post
Share on other sites

Just add an id field to your news table, and give it an id field (make it the primary key, and make it AUTO_INCREMENT).

then use this in your query:

 

 

LIMIT 0,10 ORDER BY some_id_field DESC

Share this post


Link to post
Share on other sites

×

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.