Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <?php // require_once './Domain.php';
  2. require_once './Navigacija.php';
  3. $Domain = new Domain();
  4. $file = fopen("Navigacijos.txt", "r");
  5.  
  6. while (!feof($file)) {
  7. $line = fgets($file);
  8. $items = explode(";", $line);
  9. $item = new Navigacija($items[0], $items[1], $items[2], $items[3]);
  10. }
  11. //var_dump()
  12. fclose($file);
  13. ?>
  14.  
  15. <?php
  16. $criteriaErr = "";
  17. $criteria = null;
  18.  
  19. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  20. if (empty($_POST["criteria"])) {
  21. $criteriaErr = "Name is required";
  22. } else {
  23. $criteria = test_input($_POST["criteria"]);
  24. }
  25. }
  26.  
  27. function test_input($data) {
  28. $data = trim($data);
  29. $data = stripslashes($data);
  30. $data = htmlspecialchars($data);
  31. return $data;
  32. }
  33. ?>
  34. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
  35. <input type="text" name="criteria" value="<?php echo $criteria; ?>">
  36. <span class="error">* <?php echo $criteriaErr; ?></span>
  37. <br><br>
  38. <input type="submit" name="submit" value="Submit">
  39. </form>
  40.  
  41.  
  42.  
  43. <?php
  44. require_once './Domain.php';
  45. require_once './Navigacija.php';
  46. $Domain = new Domain();
  47. $file = fopen("Navigacijos.txt", "r");
  48. while (!feof($file)) {
  49. $line = fgets($file);
  50. $items = explode(";", $line);
  51. $item = new Navigacija($items[0], $items[1], $items[2], $items[3]);
  52. $Domain->insert_into_array($item);
  53. }
  54.  
  55. function print_values($Domain) {
  56. for ($i = 0; $i < $Domain->get_count_elements(); $i++) {
  57. $object_to_array = ((array) $Domain->get_element($i));
  58. echo $object_to_array['brand'] . " " . $object_to_array['model'] . " " . $object_to_array['maps_number'] . " " . $object_to_array['price'] . "<br>";
  59. }
  60. }
  61. print_values($Domain);
  62. echo "<br>";
  63. echo "<br>";
  64. echo "<br>";
  65. //var_dump($Domain);
  66.  
  67.  
  68. if(isset($criteria)){
  69. for ($i = 0; $i < $Domain->get_count_elements(); $i++) {
  70. $object_to_array = ((array) $Domain->get_element($i));
  71. // var_dump($object_to_array);
  72. if ((int)$criteria > (int)$object_to_array['price']) {
  73. $Domain->delete_from_array($i);
  74.  
  75. }
  76. } print_values($Domain);
  77. }
  78.  
  79.  
  80.  
  81.  
  82. fclose($file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement