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 1072979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:55:55+00:00 2026-05-16T20:55:55+00:00

Please, show me how to get a random question, ‘$randomQuestion'(i.e., What color is the

  • 0

Please, show me how to get a random question, ‘$randomQuestion'(i.e., “What color is the sky?”), and matching answer, $matchingAnswer, from the quizID section of my SQL database, and then use jQuery to refresh the form, only? I started by creating the form and some JavaScript that may work.

FORM:

<form name="$quizID" action="http://asite.com" method="post">
  <fieldset>
    <legend="$randomQuestion">
    <p>
      <label>Answer: <input type="text" id="answer" onkeydown="submitAns(submit.id)" /></label>
    </p>
  </fieldset>
</form>

JS:

function submitAns(id) {
  if (document.getElementById(id).value=="$matchingAnswer")
          document.a.submit();
}

JQUERY:

$.post('get-question_matchinganswer_for_quizID.php', {
  quizID: $quizID,
  question },
  function(data) {
    alert('Question is: ' + data.question)
    alert('Answer is: ' + data.answer)
  },
  'json'
);

PHP:

<!-- Help -->
function random_row($table, $column) {
  $max_sql = "SELECT max(" . $column . ") 
          AS max_id
          FROM " . $table;
  $max_row = mysql_fetch_array(mysql_query($max_sql));
  $random_number = mt_rand(1, $max_row['max_id']);
  $random_sql = "SELECT * FROM " . $table . "
          WHERE " . $column . " >= " . $random_number . " 
          ORDER BY " . $column . " ASC
          LIMIT 1";
  $random_row = mysql_fetch_row(mysql_query($random_sql));
  if (!is_array($random_row)) {
    $random_sql = "SELECT * FROM " . $table . "
            WHERE " . $column . " < " . $random_number . " 
            ORDER BY " . $column . " DESC
            LIMIT 1";

    $random_row = mysql_fetch_row(mysql_query($random_sql));
  }
  return $random_row;
}

$randomQuestion =
$matchinAnswer =

This is extremely complicated for me, and I’ve been having a world of trouble with it. PLEASE, comment. Thank you.

  • 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-05-16T20:55:56+00:00Added an answer on May 16, 2026 at 8:55 pm

    Well to start with, your HTML is invalid: You’re not closing your tags:

    <form name="$quizID" action="http://asite.com" method="post">
        <fieldset>
            <legend><?php echo $randomQuestion?></legend>
            <label>
                Answer: <input type="text" id="answer"
                               onkeydown="submitAns(submit.id)" />
            </label>
        </fieldset>
    </form>
    

    As for the ajax, I would suggest using jQuery. It makes things much easier.

    $.post('getqidqandanswer.php', {
        quizID: 1337,
        questionID: 42},
        function(data) {
            alert('Question is: ' + data.question)
            alert('Answer is: ' + data.answer)
        },
        'json'
    );
    

    PHP:

    $quizID = isset($_POST['quizID']) ? $_POST['quizID'] : null
    $questionID = isset($_POST['questionID']) ? $_POST['questionID'] : null
    
    if($quizID && $questionID)
    {
       $data = getQuestionData($quizID, $questionID)
    }
    elseif($quizID)
    {
       $data = getRandomQuestionData($quizID)
    }
    else
    {
        $data = array(
            'question' => '',
            'answer'   => ''
        )
    }
    
    echo json_encode($data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me how to show all privileges/rules from a specific user
Can someone please show me a code example about how to get a long
Could somebody please show code which would do this quickly? Assume we get three
Could someone please show me a MySQL statement that will get the value of
Can someone please show me how I can get my JSON data and use
Could please show me code how to get this type of effect? I have
Can someone please show me how to get to label1 inside the iframe via
Please show me how i should correctly execute system proccess in java. I would
Please show me how to rewrite toString in a functional way. The code is
can someone please show me documentation on this method? i have the following line:

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.