Jump to content

decboys515

New Members
  • Posts

    3
  • Joined

  • Last visited

decboys515's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. no on the looping which is probably a significant issue since it's suppose to output a total of 5 questions. this is my first crack at working with databases so i'm a little confused and i'm not sure how to use a join.
  2. @strider64 it's set where it pulls all the questions but it only displays one. thank you for giving it a glance and for the links, i'll check those out now.
  3. I'm working on this quiz. Something has gone wrong with my form though. The page displays a random question but instead of showing 4 different answer options, it repeats one option 4 times. How do should I go about fixing this? <?php SESSION_START(); //Connect to MySQL: $con = new mysqli("localhost", "root", "", "quizproject"); ?> <html> <body> <h1>Hello, <?php echo $_SESSION["fname"]; " " ?> <?php echo $_SESSION["lname"]; ?>.</h1> <p><h2>Quiz Time! Please answer each of the following questions:</h2><br> <?php //retrieve question list: $get_questions = $con->prepare("SELECT question_ID, question FROM questions"); $get_questions->execute(); $get_questions->bind_result($question_ID, $question); $questions = array(); while ($get_questions->fetch()) { $questions[$question_ID] = array($question_ID, $question, array()); } // retrieve answer list: $get_answers = $con->prepare("SELECT id, question_ID, answers, correct FROM answers"); $get_answers->execute(); $get_answers->bind_result($id, $question_ID, $answers, $correct); while ($get_answers->fetch()) { $questions[$question_ID][2][$id] = array($id, $answers, $correct); } // Scramble the array and print: shuffle($questions); ?> <form method="get" action="result.php"> <div class="question"> <label><h2><?php echo $question ?></h2></label> <br> <input type="hidden" name="question<?php echo $question_ID ?>_id" value="<?php echo $question_ID; ?>" id="question<?php echo $question_ID; ?>_id"/> <input name="answer<?php echo $id ?>" id="q<?php echo $id ?>_a1" value="1" type="radio"/> <label for="q<?php echo $id ?>_a1"> <?php echo $answers ?></label><br> <input name="answer<?php echo $id?>" id="q<?php echo $id ?>_a2" value="2" type="radio"/> <label for="q<?php echo $id ?>_a2"> <?php echo $answers ?></label><br> <input name="answer<?php echo $answers ?>" id="q<?php echo $id ?>_a3" value="3" type="radio"/> <label for="q<?php echo $id ?>_a3"> <?php echo $answers ?></label><br> <input name="answer<?php echo $id ?>" id="q<?php echo $id ?>_a4" value="4" type="radio"/> <label for="q<?php echo $id ?>_a4"> <?php echo $answers ?></label><br> </div> <?php echo "<br><input name=\"submit\" type=\"submit\" value=\"Submit\">"; echo "</form></body></html>"; ?> </form> </html> </body>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.