Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <?php
- //вытащить все студенты по номеру группы -- lab 2
- $servername = "localhost";
- $username = "user";
- $password = "user";
- $dbname = "xxx";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- else {
- //dump from students, not results
- $group = intval($_POST['Groups_dropdown']); // Storing Selected Value In Variable
- if ($group == 0)
- echo "You have selected all students <br />";
- else
- echo "You have selected :" .$group . "<br />"; // Displaying Selected Value
- echo "<table>";
- echo "<tr>";
- echo "<td>Student id</td>";
- echo "<td>Last name</td>";
- echo "<td>First name</td>";
- echo "<td>Second name</td>";
- echo "<td>Group</td>";
- echo "</tr>";
- //$group = $_POST['get_group'];
- $sql = "SELECT * FROM students"; //all results
- $results_data = $conn->query($sql);
- if ($results_data->num_rows > 0)
- {
- while($results = $results_data->fetch_assoc() ) //while results != 0
- {
- $temp = $results["group_number"];//students group number
- $sql = "SELECT * FROM groups WHERE groups.id='$temp'";
- $results_data_groups = $conn->query($sql);
- $results_groups = $results_data_groups->fetch_assoc();
- if ($group == 0) {
- echo "<tr>";
- echo "<td>" .$results["id"]. "</td>";
- echo "<td>" .$results["last_name"]. "</td>";
- echo "<td>" .$results["first_name"]. "</td>";
- echo "<td>" .$results["second_name"]. "</td>";
- echo "<td>" .$results_groups["group_name"]. "</td>";
- echo "</tr>";
- }
- else if ($results_groups["group_name"] == $group)
- {
- echo "<tr>";
- echo "<td>" .$results["id"]. "</td>";
- echo "<td>" .$results["last_name"]. "</td>";
- echo "<td>" .$results["first_name"]. "</td>";
- echo "<td>" .$results["second_name"]. "</td>";
- echo "<td>" .$results_groups["group_name"]. "</td>";
- echo "</tr>";
- }
- }//while
- echo "</table><br />";
- }//if
- else
- {
- echo "0 results";
- }
- }
- $conn->close();
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement