开发者

Display a random quote from MySQL without repeating

I am trying to make a quote page. I would like it to show a random quote every time the page loads but also have a "Next Quote" button that changes to another random quote without repeating, unless of coarse you have gone th开发者_开发知识库rough all the quotes. I have been trying for a few days now and haven't gotten anywhere past loading a random quote on page load. If someone could please help me. Thanks.


There are a couple of ways to do it.

  1. Mark which ones the user has already seen, then when you do a SELECT, filter out the ones the user already saw.

  2. Pre-create the random order, then keep track of which quote the user last viewed. For example, quote #8. You then show quote #9 next time. Whether y


Assuming web pages and a limited number of quotes, I would just load them all into the html on the page load, and then loop through them with a slider.

What you could also do, is just load one randomly into the page and then provide the rest via xml or json. That way if the user doesn't have javascript (though rare) or a screen reader (accessibility for disabled users) they will hear / see only one quote, and then with javascript you can load in the rest of the quotes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜