Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- connect.php
- <?php
- $host="localhost";
- $db_user="root";
- $db_password="";
- $db_name="ocenyPAI";
- ?>
- --------------
- index.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Szczury, oceny</title>
- </head>
- <body>
- <form action="opcja1.php" method="get">
- <button type="submit">Pokaż wszystkich uczniów, którzy mają chociaż jedną ocenę niedostateczną</button><br>
- <button type="submit" formaction="opcja2.php">Pokaż wszystkie oceny dla jednego wskazanego ucznia</button>
- </form>
- <?php
- ...
- ?>
- -------------
- opcja1.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Nieuki i leserzy</title>
- <style>
- table, th, td {
- border: 1px solid black;
- text-align: left;
- }
- table {
- width: 100%;
- }
- td {
- height: 50px;
- vertical-align: bottom;
- width: 50px;
- }
- </style>
- </head>
- <body>
- </body>
- </html>
- <?php
- require_once "connect.php";
- $polaczenie=@new mysqli($host,$db_user,$db_password,$db_name);
- if($polaczenie->connect_errno!=0){
- echo "Błąd: ".$polaczenie->connect_errno;
- }
- else {#nie chcąc czasu na walkę z sql-owym regexem użyłem 'OR'
- if($rezultat=@$polaczenie->query("SELECT uczen FROM tabela WHERE
- 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")){
- if($rezultat->num_rows>0){
- while($row=mysqli_fetch_row($rezultat)){
- echo "<table><tr>";
- for($i=0;$i<count($row);$i++){
- print_r("<td>");
- print_r($row[$i].", ");
- print_r("</td>");
- #echo "<br>";
- }
- echo "</tr></table>";
- } $rezultat ->free_result();
- }else '<p style="color: rgb(14,114,88)">brak danych</p>';
- }
- else{
- echo '<p style="color: rgb(13,113,213)">Kwerenda niepoprawna składniwo</p>';
- }
- $polaczenie->close();
- }
- ?>
- -----------------
- opcja2.php
- <?php
- require_once "connect.php";
- $polaczenie=@new mysqli($host,$db_user,$db_password,$db_name);
- if($polaczenie->connect_errno!=0){
- echo "Błąd: ".$polaczenie->connect_errno;
- }
- else {#nie chcąc czasu na walkę z sql-owym regexem użyłem 'OR'
- if($rezultat=@$polaczenie->query("SELECT uczen FROM tabela WHERE
- 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")){
- if($rezultat->num_rows>0){
- print_r ("<form action='' method='post'>");
- echo "<select name='uczen'>";
- $j=1; #pomocnicza
- while($row=mysqli_fetch_row($rezultat)){
- for($i=0;$i<count($row);$i++){
- print_r("<option value='".$j."'>".$row[$i]);
- print_r("</option>");
- $j=$j+1;
- }
- } echo "</select>";
- echo "<input type='submit' value='Wyslij'></form>";
- $rezultat ->free_result();
- }}
- if($rezultat=@$polaczenie->query("SELECT * FROM tabela WHERE Nr=".$_POST['uczen'])){
- if($rezultat->num_rows>0){
- while($row=mysqli_fetch_row($rezultat)){
- echo "<table><tr>";
- for($i=0;$i<count($row);$i++){
- print_r("<td>");
- print_r($row[$i].", ");
- print_r("</td>");
- #echo "<br>";
- }
- echo "</tr></table>";
- }
- #$rezultat ->free_result();
- }
- $polaczenie->close();
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement