Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. $con = mysqli_connect('localhost','root','','imetrics') or die ("Cannot connect to database");
  4. if(!$con){
  5. echo ('Could not connect: ' . mysqli_error($con));
  6. }
  7.  
  8. $id= isset($_GET["q"])?intval($_GET["q"]):"";
  9.  
  10. $query = mysqli_query($con, "SELECT * FROM question WHERE question_id = '".$id."'");
  11.  
  12. function displayOption($i, $value, $answer_type) {
  13. if($value == null) {
  14. return;
  15. }
  16.  
  17. if($answer_type == "radiobutton") {
  18. echo '<input type="radio" name="rinput" value="'.htmlspecialchars($value, ENT_QUOTES).'">'.htmlspecialchars($value).'<br>';
  19. } else if($answer_type == "checkbox") {
  20. echo '<input type="checkbox" name="cinput['.$i.']" value="'.htmlspecialchars($value, ENT_QUOTES).'">'.htmlspecialchars($value).'<br>';
  21. }
  22. }
  23.  
  24. while($row = mysqli_fetch_assoc($query)) {
  25. for($i = 1; $i<=10; ++$i) {
  26. displayOption($i, $row["Option_$i"], $row['answer_type']);
  27. }
  28. }
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement