Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.24 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $dbname="colocviu";
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password,$dbname);
  10. // Check connection
  11. if ($conn->connect_error) {
  12.     echo "<h1>Connection failed</h1>";
  13.     die("Connection failed: " . $conn->connect_error);
  14. }
  15. echo "<h1>Connected successfully</h1>";
  16.  
  17.  
  18. ?>
  19.  
  20.  
  21. <html>
  22. <head>
  23.     <style>
  24.         table, th,td{
  25.             border: 1px solid black;
  26.             border-collapse: collapse;
  27.         }
  28.         th,td{
  29.             text-align: center;
  30.         }
  31.     </style>
  32. </head>
  33.  
  34. <body>
  35.  
  36. <h1> Se vor afisa biletele cu sursa si destinatia dorita</h1>
  37.  
  38. <form action="Exercitiul3a.php" method="GET">
  39.  
  40.     <label>Sursa:</label> <input type="text" name="sursa" placeholder="Type a value" /></label><br>
  41.     <label>Destinatia:</label> <input type="text" name="destinatia" placeholder="Type a value" /></label>
  42.     <input  type="submit"  ><br>
  43.  
  44.  
  45.  
  46. </form>
  47. <?php
  48. //$sursa=null;
  49. //$query=null;
  50. if(isset($_GET['sursa']) and isset($_GET["destinatia"]))
  51. {
  52.     $sursa = $_GET['sursa'];
  53.     $destinatia=$_GET['destinatia'];
  54.     $query="SELECT *
  55.            FROM Bilete
  56.            WHERE CONCAT(sursa)LIKE '%" .$sursa."%' AND CONCAT(destinatia)LIKE '%" .$destinatia."%'";
  57.     $search_result = filterTable($query);
  58. }
  59. else{$query="Select * from Bilete";
  60.     $search_result = filterTable($query);}
  61.  
  62. //$sursa=null;
  63.  
  64. function filterTable($query)
  65. {
  66.  
  67.  
  68.     $conn =mysqli_connect('localhost', 'root', '', 'colocviu');
  69.     $filter_Result = mysqli_query($conn, $query) or die('error');
  70.     return $filter_Result;
  71. }
  72.  
  73.  
  74. echo "<table style='width:100%'>";
  75. echo "<tr>
  76.        <th>nrbilet</th>
  77.         <th>sursa</th>
  78.          <th>destinatia</th>
  79.    </tr>";
  80.  
  81. while ($row = mysqli_fetch_array($search_result, MYSQLI_ASSOC)) {
  82.  
  83.     echo "<tr>
  84.        <td>";
  85.     echo $row['nrbilet'];
  86.     echo "</td>";
  87.  
  88.     echo
  89.     "<td>";
  90.     echo $row['sursa'];
  91.     echo "</td>";
  92.  
  93.     echo "<td>";
  94.     echo $row['destinatia'];
  95.     echo "</td>
  96.    </tr>";
  97. }
  98.  
  99.  
  100. echo "</table>";
  101.  
  102. ?>
  103.  
  104. <h2><form action="Meniu.html" class="button">
  105.         <input type="submit" value="Inapoi la meniu">
  106.     </form></h2>
  107.  
  108. </body>
  109. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement