Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="utf-8" />
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <title>Page Title</title>
  7.     <meta name="viewport" content="width=device-width, initial-scale=1">
  8.     <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
  9.     <script src="main.js"></script>
  10. </head>
  11. <body>
  12.     <?php
  13.     $file = fopen("cars.txt", "r");
  14.    
  15.     $marke = array();
  16.     $zemlje = array();
  17.     while(!feof($file)){
  18.         $red = explode("\t", fgets($file));
  19.         if(!in_array($red[1], $marke)){
  20.             array_push($marke, $red[1]);
  21.         }
  22.         if(!in_array($red[6], $zemlje)){
  23.             array_push($zemlje, $red[6]);
  24.         }
  25.     }
  26.  
  27.     if(!$_POST){
  28.     ?>
  29.  
  30.     <form method="post" action="">
  31.         <select name="marka">
  32.             <?php
  33.             foreach($marke as $m){
  34.                 echo '<option value="'.$m.'">'.$m.'</option>';
  35.             }
  36.             ?>
  37.         </select>
  38.         <select name="zemlja">
  39.             <?php
  40.             foreach($zemlje as $z){
  41.                 echo '<option value="'.$z.'">'.$z.'</option>';
  42.             }
  43.             ?>
  44.         </select>
  45.         <input type="submit">
  46.     </form>
  47.     <?php
  48.     }
  49.     if($_POST){
  50.         $file = fopen("cars.txt", "r");
  51.         $brojac = 0;
  52.         $polje = [];
  53.         $zemlja = $_POST['zemlja'];
  54.         $marka = $_POST['marka'];
  55.         echo '<table>';
  56.  
  57.         while(!feof($file)){
  58.             $red = explode("\t", fgets($file));
  59.             if($red[1] == $marka){
  60.                 if($red[6] == $zemlja){
  61.                     $brojac++;
  62.                     echo '<tr><td>'.$red[2].'</td><td>('.$brojac.')</td></tr>';
  63.                 }
  64.                
  65.             }
  66.         }
  67.  
  68.         echo '</table>';
  69.  
  70.         //var_dump($polje);
  71.     }
  72.     ?>
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement