So the situation I have is I’m using WordPress and I’m trying to write a custom plugin.
What I want to do is grab an array of all the posts and show the first 25.
Then underneath that I want to have a button that says , “Show Next 25” and when I hit the button it will add the next 25 to the list of articles, and if I hit again, wash , rinse repeat till it’s out of articles.
I was going to write this in straight PHP / MySQL but not sure how to incorporate JQuery into it.
My thought was to write a series of offsetting MYSQL statements but thats probably too clunkly.
My 2nd thought was to pull all the post info into one Associative array and then find a way to parse the other output into the hidden divs.
Thoughts?
I tried looking for a wordpress plugin that does this but did not find one and I tried searching for a situation like this on here, found some stuff similar but not the same.
I guess you could compare this to commenting feature where it shows the last 10 commends and you have hit a button to see the rest of the comments.
Thanks much in advance.
I would grab from the database only 25 at a time. Then I might use JQuery to do the ajax call to pull another 25 based on what has already been shown.
Use a limit 25, offset clause on the mysql. Send the next offset value to the web page as a hidden input or a javascript var. Then use JQuery ajax to call your php function that returns a JSON data of the next 25 rows to display.
So this isn’t JQuery, but I like this:
http://www.kryogenix.org/code/browser/sorttable/
But I also agree w/ the thoughts, you’re wasting the resources of Ajax if you do it this way. Ajax would do well here.
Here’s how “I” would do it, though this is just a suggestion.
First, if you don’t already have it, I would suggest something like Komodo Edit to code in. It’s free, but I have the pay for for very cheap (i think my last upgrade lic was 30 bucks?). If you, buy just one copy, they’ll offer you a ton of discounts if you ever decide not to upgrade. Good program for HTML5/php editing.
Second, go look at Codeigniter’s Active Record. After looking this page over, you’ll see very easily why I would suggest CI. CI’s Active Record makes safe and secure SQL calls an absolute breeze, though for better security, I would suggest you make use of there XML filter and never “chain” Active Record calls as it shows you can do on that page.
Finally, as I said before, I would read up on jQuery‘s .ajax(), .get(), and .post() commands. After a stirring read, I’d probably end up using .get() to make calls to a controller containing a simple php active record function that would return the wanted update data at +25 “ahead” of what the user is actually looking at.