I am writing an application which shows a user one thing to vote on, at a time. I have a MySQL table which contains these things. Right now I have it set up so that upon login, I query my database to get a limited number of these things, and then I use PHP to turn that into an array. After a user submits a vote, the thing they’ve already voted on is ‘unset’ from the array. When the new array size is one, I query my database to create a new array.
Is this a ‘bad’ way to do it? Should I instead just query my database to get a new thing for the user to vote on after every time they submit a vote?
Any help/suggestions appreciated.
This will likely get closed because it’s subjective…
IMHO, it’s all a matter of how you want it to function. Typically, in standard programming, I suggest loading everything up-front so that once loaded, the user’s experience is very smooth and without loading.
In Web programming, however, using AJAX or something similarly asynchronous to dynamically modify/rebuild the array as you need is certainly acceptable, especially if the end result is functioning in a way you’re happy with.
Bottom line: Either way will work – it depends on your needs.