Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "palo";
- $conn= mysqli_connect($servername, $username, $password, $dbname);
- if(!$conn){
- die("Connection failed: ". mysqli_connect_error());
- }
- $sql = "SELECT test_id, question, optiona, optionb, optionc, optiond FROM tquestions ORDER BY RAND() LIMIT 1";
- $result = mysqli_query ($conn, $sql); // Run the query
- if (!$result) {
- printf("Error: %sn", mysqli_error($conn));
- exit();
- }
- ?>
- <script>
- function openTab(evt, tabName) {
- var i, tabcontent, tablinks;
- tabcontent = document.getElementsByClassName("tabcontent");
- for (i = 0; i < tabcontent.length; i++) {
- tabcontent[i].style.display = "none";
- }
- tablinks = document.getElementsByClassName("tablinks");
- for (i = 0; i < tablinks.length; i++) {
- tablinks[i].className = tablinks[i].className.replace(" active", "");
- }
- document.getElementById(tabName).style.display = "block";
- evt.currentTarget.className += " active";
- }
- document.getElementById("defaultOpen").click();
- </script>
- <div class="tab">
- <button class="tablinks" onclick="openTab(event, 'q1')" id="defaultOpen">1</button>
- <button class="tablinks" onclick="openTab(event, 'q2')">2</button>
- <button class="tablinks" onclick="openTab(event, 'q3')">3</button>
- </div>
- <?php if (!empty($_SESSION['msg'])) { ?>
- <div class="alert alert-info"><?php echo $_SESSION['msg']; ?></div>
- <?php } ?>
- <div id="q1" class="tabcontent">
- <table class="table table-hover">
- <tbody>
- <?php if (mysqli_num_rows($result) > 0): ?>
- <?php foreach ($result as $results):?>
- <tr class="form-group">
- <h3 name="ques[<?php echo $test_id;?>]" style="text-indent: 40px;"> <?php echo $results['question']; ?> </h3>
- </tr>
- <tr class="form-group">
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" name="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optiona'];?>"><?php echo $results['optiona'];?>
- </label>
- <br>
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" name="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optionb'];?>"><?php echo $results['optionb'];?>
- </label>
- <br>
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" name="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optionc'];?>"><?php echo $results['optiond'];?>
- </label>
- <br>
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" ame="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optiond'];?>"><?php echo $results['optiond'];?>
- </label>
- <br>
- </tr>
- <?php endforeach ?>
- <?php endif ?>
- </tbody>
- </table>
- </div>
- <div id="q2" class="tabcontent">
- <table class="table table-hover">
- <tbody>
- <?php if (mysqli_num_rows($result) > 0): ?>
- <?php foreach ($result as $results):?>
- <tr class="form-group">
- <h3 name="ques[<?php echo $test_id;?>]" style="text-indent: 40px;"> <?php echo $results['question']; ?> </h3>
- </tr>
- <tr class="form-group">
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" name="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optiona'];?>"><?php echo $results['optiona'];?>
- </label>
- <br>
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" name="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optionb'];?>"><?php echo $results['optionb'];?>
- </label>
- <br>
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" name="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optionc'];?>"><?php echo $results['optiond'];?>
- </label>
- <br>
- <label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
- <input style="font-size: 18px;" type="radio" ame="ans[<?php echo $results['test_id'];?>" value="<?php echo $results['optiond'];?>"><?php echo $results['optiond'];?>
- </label>
- <br>
- </tr>
- <?php endforeach ?>
- <?php endif ?>
- </tbody>
- </table>
- </div>
Add Comment
Please, Sign In to add comment