Guest User

Untitled

a guest
Jun 23rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
  2. <meta charset="UTF-8">
  3.  
  4. `<?php
  5. //Create connection credentials
  6. $db_host = 'localhost';
  7. $db_name = 'quizzer';
  8. $db_user = 'root';
  9. $db_pass = '';
  10.  
  11. $mysqli = new mysqli ($db_host, $db_user, $db_pass, $db_name);
  12.  
  13. if($mysqli->connect_error){
  14. printf("Connect failed: %sn", $mysqli->connect_error);
  15. exit();
  16. }
  17.  
  18. //Set question number
  19. $number = (int) $_GET['n'];
  20.  
  21. /*
  22. * Get total questions
  23. */
  24. $query = "SELECT * FROM `questions`";
  25. //Get result
  26. $results = $mysqli->query($query) or die($mysqli->error.__LINE__);
  27. $total = $results->num_rows;
  28.  
  29. /*
  30. * Get Question
  31. */
  32. $query = "SELECT * FROM `questions`
  33. WHERE question_number = $number";
  34. //Get result
  35. $result = $mysqli->query($query) or die($mysqli->error.__LINE__);
  36.  
  37. $question = $result->fetch_assoc();
  38.  
  39. /*
  40. * Get Choices
  41. */
  42. $query = "SELECT * FROM `choices`
  43. WHERE question_number = $number";
  44. //Get results
  45. $choices = $mysqli->query($query) or die($mysqli->error.__LINE__);
  46.  
  47.  
  48. <?php $question['question_number']; ?> of <?php echo $total; ?>
  49.  
  50. <?php echo $question['text']; ?>
  51.  
  52. <?php while($row = $choices->fetch_assoc()): ?>
  53.  
  54. <?php echo $row['id']; ?>" /><?php echo $row['text']; ?>
  55.  
  56. <?php endwhile; ?>`
Add Comment
Please, Sign In to add comment