Advertisement
RAYCHEV

1.2ColorCars.php

Feb 2nd, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Rich People`s Problems</title>
  5.     <style>
  6.         table {
  7.             margin-top:40px;
  8.         }
  9.         td, th {
  10.             padding:5px;
  11.         }
  12.     </style>
  13. </head>
  14. <body>
  15. <form action="" method="post" >
  16.     <label for="cars">Enter Cars</label>
  17.     <input type="text" name="cars"  value="shkoda, filicia, moskvich"/>
  18.     <input type="submit" value="Show Results"/>
  19. </form>
  20. <?php
  21. if(isset($_POST['cars']) && !empty($_POST['cars'])) {
  22.     $allCars = explode(',', $_POST['cars']);
  23.  
  24.     $allColors = array('aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy',
  25.         'olive', 'orange', 'purple', 'red', 'silver', 'teal', 'white', 'yellow');
  26.  
  27.     $resultTable = '';
  28.     echo "<table border='1'><tr><td>Car</td><td>Color</td><td>Count</td></tr>";
  29.  
  30.     for($i = 0; $i < count($allCars) ;$i++) {
  31.         $color = $allColors[rand(0, 16)];
  32.         $count = rand(1, 5);
  33.         echo  "<tr><td>$allCars[$i]</td><td>$color</td><td>$count</td></tr>";
  34.     }
  35.  
  36.     echo "</table>";
  37.  
  38. }
  39. ?>
  40.  
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement