title: Help With PHP Pagination Script For Flat File Database
body: <p>I have a few questions regarding a PHP Pagination Script For Flat File Database I found.
  I have posted the script below.</p>
  
  <pre><code>&lt;?php 
  echo '&lt;html&gt;&lt;body&gt;';
  
  // Data, normally from a flat file or some other source  
  $data = "Item1|Item2|Item3|Item4|Item5|Item6|Item7|Item8|Item9|Item10";  
  // Put our data into an array  
  $dataArray = explode('|', $data);  
  // Get the current page  
  $currentPage = trim($_REQUEST[page]);  
  // Pagination settings  
  $perPage = 3;  
  $numPages = ceil(count($dataArray) / $perPage);  
  if(!$currentPage || $currentPage &gt; $numPages)  
      $currentPage = 0;  
  $start = $currentPage * $perPage;  
  $end = ($currentPage * $perPage) + $perPage;  
  // Extract ones we need  
  foreach($dataArray AS $key =&gt; $val)  
  {  
      if($key &gt;= $start &amp;&amp; $key &lt; $end)  
          $pagedData[] = $dataArray[$key];  
  }
  
  foreach($pagedData AS $item)  
      echo '&lt;a href="/'. $item .'/index.php"&gt;'. $item .'&lt;/a&gt;&lt;br&gt;';
  
  if($currentPage &gt; 0 &amp;&amp; $currentPage &lt; $numPages)  
      echo '&lt;a href="?page=' . ($currentPage - 1) . '"&gt;« Previous page&lt;/a&gt;&lt;br&gt;';  
  if($numPages &gt; $currentPage &amp;&amp; ($currentPage + 1) &lt; $numPages)  
      echo '&lt;a href="?page=' . ($currentPage + 1) . '" class="right"&gt;Next page »&lt;/a&gt;&lt;br&gt;';
  
  echo '&lt;/body&gt;&lt;/html&gt;';
  ?&gt;
  </code></pre>
  
  <p>My first problem seems to be in line 9. I could change the line to:</p>
  
  <pre><code>$currentPage = trim(@$_REQUEST[page]);
  </code></pre>
  
  <p>But this change won't fix the error, it will just hide it. What needs to be done to line 9 to rid my page of the error?</p>
  
  <p>Secondly, I would like to fetch the data on line 5 in a different way. I would like to get the data from a text file, let's call it "items.txt", that has entries like below, one per line.</p>
  
  <pre><code>Fun
  Games
  Toys
  Sports
  Fishing
  Pools
  Boats
  </code></pre>
  
  <p>Please recommend alternate code to fetch the desired data.</p>
  
  <p>Lastly, I would like to include links to the "First page" and "Last page" as well as "Previous page" and "Next page", as is the current code. </p>
  
  <p>I apologize for my sloppy posting, but would be real appreciative of anybody who could help me understand the changes needed to produce my desired results. Thanks.....</p>