Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <html>
  2. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  3.  
  4. <?php
  5.  
  6. //вытащить все студенты по номеру группы -- lab 2
  7. $servername = "localhost";
  8. $username = "user";
  9. $password = "user";
  10. $dbname = "xxx";
  11. // Create connection
  12. $conn = new mysqli($servername, $username, $password, $dbname);
  13. // Check connection
  14. if ($conn->connect_error) {
  15. die("Connection failed: " . $conn->connect_error);
  16. }
  17. else {
  18.  
  19. //dump from students, not results
  20.  
  21. $group = intval($_POST['Groups_dropdown']); // Storing Selected Value In Variable
  22. if ($group == 0)
  23. echo "You have selected all students <br />";
  24. else
  25. echo "You have selected :" .$group . "<br />"; // Displaying Selected Value
  26.  
  27. echo "<table>";
  28. echo "<tr>";
  29. echo "<td>Student id</td>";
  30. echo "<td>Last name</td>";
  31. echo "<td>First name</td>";
  32. echo "<td>Second name</td>";
  33. echo "<td>Group</td>";
  34. echo "</tr>";
  35.  
  36. //$group = $_POST['get_group'];
  37. $sql = "SELECT * FROM students"; //all results
  38. $results_data = $conn->query($sql);
  39.  
  40.  
  41. if ($results_data->num_rows > 0)
  42. {
  43. while($results = $results_data->fetch_assoc() ) //while results != 0
  44. {
  45.  
  46. $temp = $results["group_number"];//students group number
  47. $sql = "SELECT * FROM groups WHERE groups.id='$temp'";
  48. $results_data_groups = $conn->query($sql);
  49. $results_groups = $results_data_groups->fetch_assoc();
  50.  
  51. if ($group == 0) {
  52. echo "<tr>";
  53. echo "<td>" .$results["id"]. "</td>";
  54. echo "<td>" .$results["last_name"]. "</td>";
  55. echo "<td>" .$results["first_name"]. "</td>";
  56. echo "<td>" .$results["second_name"]. "</td>";
  57. echo "<td>" .$results_groups["group_name"]. "</td>";
  58. echo "</tr>";
  59.  
  60. }
  61. else if ($results_groups["group_name"] == $group)
  62. {
  63.  
  64. echo "<tr>";
  65. echo "<td>" .$results["id"]. "</td>";
  66. echo "<td>" .$results["last_name"]. "</td>";
  67. echo "<td>" .$results["first_name"]. "</td>";
  68. echo "<td>" .$results["second_name"]. "</td>";
  69. echo "<td>" .$results_groups["group_name"]. "</td>";
  70. echo "</tr>";
  71.  
  72. }
  73. }//while
  74. echo "</table><br />";
  75. }//if
  76. else
  77. {
  78. echo "0 results";
  79. }
  80. }
  81. $conn->close();
  82. ?>
  83.  
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement