SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    India
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    To select data randomly from database

    I am doing a quiz site using php and mysql in which i am retrieving the questions with answers randomly from the database using ORDER BY rand() LIMIT 0,1.Now my problem is that the questions are getting repeated continuously.But it should be like i must get all the questions randomly everytime but without repeating..pls help me.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Keep track of what questions you've already picked, and tell the query not to pick those again:

    SELECT question FROM table WHERE id NOT IN (1, 5, 3) ORDER BY RAND() LIMIT 1

    You can throw the questions you've already chosen into a session or hidden input on the form to get it page to page.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •