Quote:
Originally Posted by
Contrid
I want to loop through 10 MySQL records infinitely by 'order' field.
So it starts at 1, outputs something on the page.
Using Javascript setInterval and an Ajax request calling back to the script with the current order value 1.
The script will then select 2 and output on the page and the Javascript will call to the script again with order value 2.
And so it will go on until it reaches 10 and needs to then loop back to 1 since there is nothing after 10.
I can't say how many records there will be, it is dynamic but that's the concept :)
Wouldn't you just be better off retrieving all of the IDs you want to use in this process (maybe even all of the data you need) into an array and using a pointer to identify which element in the array you are currently at every time your setInterval function is called?
Depending on how much data is needed to produce your output, I'd argue you can bring back all of it and store it in a multi-dimensional array and your performance will be FAR better. Keep in mind, you are setting up a situation where each visitor will be hitting your database every X seconds automatically. Sounds costly and slow to me...
Oh, and not to mention with this setup your ability to cache the data seems limited. I imagine you can reuse the same pulled records for every one of your visitors (they don't get unique data), so by pulling them all, caching them, and then utilizing that cache, you can save a LOT of database activity. You will have 1 call every time your cache expires for all visitors instead of a call for each visitor every X seconds.
Edit:
added more to my rant regarding caching