mardi 23 février 2016

Best way to get rows based on a field value

i want to create an app for a wordpress site.

As some of u may know, wordpress posts have ID.

in my app there is a load more(btn1) and get recent post(btn2) button.

And I want to save posts in Database.

So, when user open app for the first time, user get about 15 post, so the first records in table is the most recent post in the site. (this post have id) after this, my user may want read past post(post witch they have smaller id), so user click btn1 and some post for example from yesterday load and user read the. after this user request to see the recent post, and press btn2, so new post (witch they have the biggest ID in the table) saved in my database.

for example:

user open app and get post, witch have this id: 40,45,48,49

my table: 40,45,48,49

user request more post, and the post have this IDs:

30,,29,20,19

and my table is like: 40,45,48,49,30,,29,20,19

and then user request new posts, and new posts have this IDs: 50,56,60.67

so my table is like: 40,45,48,49,30,,29,20,19, 50,56,60.67

So, now my questios is:

what is the best way or in other word, what is the most efficent way to get records based on the IDs descending order like:

67,60,56,50,4949,48,45,40,30,,29,20,19

So, rational Options are:

1-use order by

2- use 2 table

table1: recent post

table2: more post

which is better in term of ram usage and speed?

Aucun commentaire:

Enregistrer un commentaire