Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:24:46+00:00 2026-06-04T14:24:46+00:00

I already know how to do a random mysql/php query, but how do I

  • 0

I already know how to do a random mysql/php query, but how do I track what has already been queried a row isn’t pulled again. Use case: A quiz that has 10 questions. The questions need to be in random order. How can I track that questions (rows) 2,5,6,8,9 have already been answered, but questions 1,3,4,7,10 remain. Here’s what I have so far:

$current_test = $_SESSION['testid'];
// v v v query for this TEST
$tests = mysql_query("SELECT * FROM the_tests WHERE the_tests.testid=$current_test");
$test = mysql_fetch_array($tests);
// ^ ^ ^ query for this TEST


// v v v query for the QUESTIONS from this Test
// Generate
if ($test['randomize']==1){
    $offset_result = mysql_query("SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM the_questions WHERE the_questions.test_id_q=$current_test");//SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM the_questions WHERE `qid` NOT IN (1,5,6) AND the_questions.test_id_q=1
    $offset_row = mysql_fetch_object($offset_result);
    $offset = $offset_row->offset;
    $questions = mysql_query("SELECT * FROM the_questions WHERE the_questions.test_id_q=$current_test LIMIT $offset, 1 " );
}else{
    $questions = mysql_query("SELECT * FROM the_questions WHERE the_questions.test_id_q=$current_test");
}
$totalQuestions = mysql_query("SELECT * FROM the_questions WHERE the_questions.test_id_q=$current_test");
$totalQs = mysql_num_rows($totalQuestions);
$testQ = mysql_fetch_array($questions);

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:24:47+00:00Added an answer on June 4, 2026 at 2:24 pm

    Here’s what I came up with:

    Assuming $_SESSION[‘qList’] is an array that looks like this:

    $_SESSION['qList'] = array(1,2,3,4,5,6,7,8,9,10);
    

    When the user submits a question, there is a <input type=”hidden” value=”5″…> where the value is the current question ID. $eliminateQ below is this question ID:

    $_SESSION['qList'] = array_diff($_SESSION['qList'],array($eliminateQ));
    $_SESSION['qList'] = array_values($_SESSION['qList']);
    $questions = mysql_query("SELECT * FROM tan_questions WHERE test_id_q=$current_test AND qid IN (".implode(',',$_SESSION[qList]).") ORDER BY RAND() LIMIT 1");
    

    This results in an updated qList array without ID number 5:

    $_SESSION['qList'] = array(1,2,3,4,6,7,8,9,10);
    

    And the whole thing goes on until no questions are left. There is an if() statement in that instance forwarding the user on to the results page. Viola!

    Thanks, @pixeline, for your insight. I took your NOT IN and reversed it to IN. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this topic has been discussed a lot , but I have a
I already know that most implementations use a single thread, but is there anything
I think I already know the answer to this but thought I would ask
I think i already know the answer to this, but i cannot find anything
As many of you may already know I have been having issues with another
I already know there's answers for this kind of thing, but I don't really
I know there are already several similar questions here, but I need some recommendations
So not to reinvent the wheel, I would like to know what has already
This question may have been asked already - but unfortunately, I could not find
I have already posted another question about this, but no one seemed to know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.