Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>TRIVIAL</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width">
  6. <link rel="stylesheet" href="css/bootstrap.min.css">
  7. <link rel="stylesheet" href="css/jquery.raty.css">
  8.  
  9. <script src="js/jquery-1.11.1.min.js"></script>
  10. <script src="js/bootstrap.min.js"></script>
  11. <script src="js/jquery.raty.js"></script>
  12.  
  13.  
  14.  
  15. </head>
  16. <body>
  17.  
  18.  
  19. <div id="preguntas"></div>
  20.  
  21. <?php
  22.  
  23. //funcion que accede a la base de datos
  24. include 'funciones.php';
  25. $conexion = conectaBBDD();
  26.  
  27. //lle da un valor random a lo que imprime la base de datos
  28. //$numero = rand(1000, 1128);
  29. $consulta = $conexion->query("SELECT * from Preguntas where tema = 'Filosofia'");
  30.  
  31. $theArray = array();
  32. $aux = 0;
  33.  
  34. while ($fila = $consulta->fetch_assoc()) {
  35.  
  36.  
  37. $theArray[$aux][0] = $fila["enunciado"];
  38. $theArray[$aux][1] = $fila["r1"];
  39. $theArray[$aux][2] = $fila["r2"];
  40. $theArray[$aux][3] = $fila["r3"];
  41. $theArray[$aux][4] = $fila["r4"];
  42. $theArray[$aux]["correcta"] = $fila["correcta"];
  43.  
  44. $aux++;
  45.  
  46. }
  47.  
  48. //
  49. // echo '<div>'.$fila["enunciado"].'</div>';
  50. // echo '<br>';
  51. // echo '<button onclick="comparar(1,'.$fila["correcta"].')">'.$fila["r1"].'</button>';
  52. // echo '<button onclick="comparar(1,'.$fila["correcta"].')">'.$fila["r2"].'</button>';
  53. // echo '<button onclick="comparar(1,'.$fila["correcta"].')">'.$fila["r3"].'</button>';
  54. // echo '<button onclick="comparar(1,'.$fila["correcta"].')">'.$fila["r4"].'</button>';
  55. // echo '<br>';
  56. // echo '<button>siguiente</button>';
  57.  
  58.  
  59. ?>
  60.  
  61. <script>
  62.  
  63. var puntuacion = 0;
  64.  
  65.  
  66. function shuffle(o){ //v1.0
  67. for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  68. return o;
  69. };
  70.  
  71. var array = <?php echo json_encode($theArray); ?>;
  72.  
  73. function preguntas(){
  74. $('#preguntas').empty();
  75.  
  76.  
  77.  
  78. shuffle(array);
  79.  
  80.  
  81. $('#preguntas').append('<button>' +array[0][0]+'</button>');
  82. $('#preguntas').append('<button onclick="comprobar(1,'+array[0]["correcta"]+')">'+array[0][1]+'</button>');
  83. $('#preguntas').append('<button onclick="comprobar(2,'+array[0]["correcta"]+')">'+array[0][2]+'</button>');
  84. $('#preguntas').append('<button onclick="comprobar(3,'+array[0]["correcta"]+')">'+array[0][3]+'</button>');
  85. $('#preguntas').append('<button onclick="comprobar(4,'+array[0]["correcta"]+')">'+array[0][4]+'</button>');
  86.  
  87. }
  88. function comprobar(var1,var2){
  89.  
  90. if(var1 === var2){
  91.  
  92. $('#preguntas').append('<button>Correcto</button>') ;
  93.  
  94. puntuacion++;
  95.  
  96. $('#puntuacion').html(puntuacion);
  97.  
  98. }else{
  99.  
  100. $('#preguntas').append('<button>Incorrecto</button>') ;
  101. }
  102.  
  103. $('#preguntas').append('<button onclick="preguntas()"> Siguiente</button>');
  104.  
  105.  
  106. }
  107.  
  108. $(document).ready(function(){
  109. preguntas();
  110. $('#puntuacion').html(puntuacion);
  111. });
  112.  
  113.  
  114. </script>
  115.  
  116. <div id="puntuacion"></div>
  117. </body>
  118.  
  119. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement