Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1. <?php
  2. session_start();  
  3.  
  4. //if(isset($_SESSION['views'])) $_SESSION['views'] = $_SESSION['views']+ 1;
  5. //else $_SESSION['views'] = 1;
  6.  
  7. /*if(isset($_SESSION['movies'])) $_SESSION['movies'] = $_SESSION['movies'];
  8. else $_SESSION['movies'] = $moviesIn;*/
  9.  
  10. if(isset($_SESSION['movies'])) $_SESSION['movies'] = $_SESSION['movies'];
  11. else $_SESSION['movies'] = GetMovies();
  12.  
  13. //print_r($_SESSION['movies']);
  14.  
  15. /*
  16. if($_POST['load'])          LoadList();
  17. else if($_POST['save'])     SaveList();
  18. else if($_POST['add'])      AddList();
  19. else if($_POST['remove'])   RemoveList();
  20. else if($_POST['clear'])    ClearList();
  21. else if($_POST['count'])    CountList();
  22. else echo "very strange error";
  23. */
  24. function GetMovies() {
  25.     //open file, get contents, close file
  26.     $filename = "./movies.in";
  27.     $handle = fopen($filename, "r");
  28.     $contents = fread($handle, filesize($filename));
  29.     fclose($handle);
  30.  
  31.     //get an array of movies
  32.     $moviesIn = explode("\n", $contents);
  33.  
  34.     //cut out that stupid newline
  35.     for($i=0; $i<count($moviesIn); $i++) {
  36.     if($i<(count($moviesIn)-1)) {$trimmed = substr($moviesIn[$i], 0, strlen($moviesIn[$i])-1);}
  37.     else {$trimmed = $moviesIn[$i];}
  38.     $moviesIn[$i] = $trimmed;
  39.     }
  40.     return $moviesIn;
  41. }
  42.  
  43. /*
  44. function LoadList() {
  45. global $output;
  46. for($i=0; $i<count($_SESSION['movies']); $i++)
  47.  $output .= "<option value=\"$i\">".$_SESSION['movies'][$i]."</option>\n";
  48.  
  49.  //return $output;
  50. }
  51.  
  52. //$_SESSION['movies'] = $_SESSION['movies'];
  53.  
  54. //print_r($_SESSION['movies']);
  55. //echo $_SESSION['movies'][0];
  56. //echo $_SESSION['movies'][1];
  57. //echo $_SESSION['movies'][2];
  58. */
  59. //check out the arrayUnique() function
  60. /**/
  61. ?>
  62. <html>
  63. <head>
  64. <title>Video Rentals</title>
  65. <style type="text/css">
  66. form {
  67.     text-align: center;
  68.     border: 1px solid;
  69.     width: 600px;
  70.     margin: 0 auto 0 auto;
  71.     }
  72.  
  73. input {
  74.     width: 160px;
  75.     margin: 0px;
  76.     }
  77. </style>
  78. </head>
  79. <body>
  80. <?php print_r($_SESSION['movies']); ?>
  81.  
  82. <form>
  83. <h1>Video Rentals</h1>
  84. <br />
  85. <br />
  86.  
  87. <input type="text" name="TBA" value="" />
  88.  
  89. <br />
  90. <select name="movies">
  91. <?php
  92. //display the dropdown box of current movies
  93. //echo $output
  94. ?>
  95. </select>
  96.  
  97. <br />
  98.  
  99. <input type="submit" name="load" value="Load Movie List" />
  100. <input type="submit" name="save" value="Save Movie list" />
  101. <input type="submit" name="add" value="Add Movie" />
  102. <br />
  103. <input type="submit" name="remove" value="Remove Movie" />
  104. <input type="submit" name="clear" value="Clear Movie List" />
  105. <input type="submit" name="count" value="Display Movie Count" />
  106.  
  107. </form>
  108.  
  109.  
  110. </body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement