Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. connect.php
  2. <?php
  3. $host="localhost";
  4. $db_user="root";
  5. $db_password="";
  6. $db_name="ocenyPAI";
  7. ?>
  8. --------------
  9. index.php
  10. <!DOCTYPE html>
  11. <html lang="en">
  12. <head>
  13. <meta charset="UTF-8">
  14. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  15. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  16. <title>Szczury, oceny</title>
  17. </head>
  18. <body>
  19. <form action="opcja1.php" method="get">
  20. <button type="submit">Pokaż wszystkich uczniów, którzy mają chociaż jedną ocenę niedostateczną</button><br>
  21. <button type="submit" formaction="opcja2.php">Pokaż wszystkie oceny dla jednego wskazanego ucznia</button>
  22. </form>
  23.  
  24. <?php
  25. ...
  26. ?>
  27. -------------
  28. opcja1.php
  29. <!DOCTYPE html>
  30. <html lang="en">
  31. <head>
  32. <meta charset="UTF-8">
  33. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  34. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  35. <title>Nieuki i leserzy</title>
  36. <style>
  37. table, th, td {
  38. border: 1px solid black;
  39. text-align: left;
  40. }
  41.  
  42. table {
  43. width: 100%;
  44. }
  45. td {
  46. height: 50px;
  47. vertical-align: bottom;
  48. width: 50px;
  49. }
  50.  
  51. </style>
  52. </head>
  53. <body>
  54.  
  55. </body>
  56. </html>
  57. <?php
  58. require_once "connect.php";
  59. $polaczenie=@new mysqli($host,$db_user,$db_password,$db_name);
  60.  
  61. if($polaczenie->connect_errno!=0){
  62. echo "Błąd: ".$polaczenie->connect_errno;
  63. }
  64. else {#nie chcąc czasu na walkę z sql-owym regexem użyłem 'OR'
  65. if($rezultat=@$polaczenie->query("SELECT uczen FROM tabela WHERE
  66. P1=1 OR P2=1 OR P3=1 OR P4=1 OR P5=1 OR P6=1 OR P7=1 OR P8=1 OR P9=1")){
  67. if($rezultat->num_rows>0){
  68. while($row=mysqli_fetch_row($rezultat)){
  69. echo "<table><tr>";
  70. for($i=0;$i<count($row);$i++){
  71. print_r("<td>");
  72. print_r($row[$i].", ");
  73. print_r("</td>");
  74. #echo "<br>";
  75. }
  76. echo "</tr></table>";
  77. } $rezultat ->free_result();
  78.  
  79. }else '<p style="color: rgb(14,114,88)">brak danych</p>';
  80. }
  81. else{
  82. echo '<p style="color: rgb(13,113,213)">Kwerenda niepoprawna składniwo</p>';
  83. }
  84. $polaczenie->close();
  85. }
  86.  
  87. ?>
  88. -----------------
  89. opcja2.php
  90. <?php
  91. require_once "connect.php";
  92. $polaczenie=@new mysqli($host,$db_user,$db_password,$db_name);
  93.  
  94. if($polaczenie->connect_errno!=0){
  95. echo "Błąd: ".$polaczenie->connect_errno;
  96. }
  97. else {#nie chcąc czasu na walkę z sql-owym regexem użyłem 'OR'
  98. if($rezultat=@$polaczenie->query("SELECT uczen FROM tabela WHERE
  99. P1=1 OR P2=1 OR P3=1 OR P4=1 OR P5=1 OR P6=1 OR P7=1 OR P8=1 OR P9=1")){
  100. if($rezultat->num_rows>0){
  101. print_r ("<form action='' method='post'>");
  102. echo "<select name='uczen'>";
  103. $j=1; #pomocnicza
  104. while($row=mysqli_fetch_row($rezultat)){
  105.  
  106. for($i=0;$i<count($row);$i++){
  107.  
  108. print_r("<option value='".$j."'>".$row[$i]);
  109. print_r("</option>");
  110. $j=$j+1;
  111. }
  112.  
  113. } echo "</select>";
  114. echo "<input type='submit' value='Wyslij'></form>";
  115. $rezultat ->free_result();
  116. }}
  117. if($rezultat=@$polaczenie->query("SELECT * FROM tabela WHERE Nr=".$_POST['uczen'])){
  118. if($rezultat->num_rows>0){
  119. while($row=mysqli_fetch_row($rezultat)){
  120. echo "<table><tr>";
  121. for($i=0;$i<count($row);$i++){
  122. print_r("<td>");
  123. print_r($row[$i].", ");
  124. print_r("</td>");
  125. #echo "<br>";
  126. }
  127.  
  128. echo "</tr></table>";
  129. }
  130.  
  131.  
  132. #$rezultat ->free_result();
  133. }
  134.  
  135. $polaczenie->close();
  136. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement