Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Thanked 0 Times in 0 Posts

    Display Random Non repeatable Array

    Hi all,

    Can someone help me with this problem of mine..
    It seems I kind of reach a stuck point..

    So, basically, I tried to create a quiz, the questions are saved inside the database. Now, I managed to get the necessary data from the database, the problem is in how to load them with this characteristic:
    - random
    - unrepeatable

    I managed to load them in random, but the data still repeatable..
    I tried to use shuffle(), rand(), array_rand() in PHP file,
    and also using order by rand() in sql query..

    But they are still repeatable..

    For information, the data will be display through flash file..

    Can somebody help me with this?

    Thanks before..
    Appreciate any help..

    Here's the code of mine

    PHP Code:
    $sqlText="SELECT * FROM soal WHERE Difficulty='"$levelStr ."' AND Topic='"$topic ."'";
    $row mysql_fetch_array($result)) {
        if (
    $count>0) {

  2. #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Denver, Colorado USA
    Thanked 511 Times in 499 Posts
    The questions repeat because each page request is completely separate from all other page requests and php has no idea that any question has already been used.

    To prevent repeats, you need to remember which of the questions have already been used. You can either use a $_SESSION variable or a database table to remember which questions have been output for any visitor.

    Someone posted a solution using $_SESSION variables in one of the other php help forums you posted on.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.


Posting Permissions

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