Help With PHP Pagination Script For Flat File Database -


i have few questions regarding php pagination script flat file database found. have posted script below.

<?php  echo '<html><body>';  // data, flat file or other source   $data = "item1|item2|item3|item4|item5|item6|item7|item8|item9|item10";   // put our data array   $dataarray = explode('|', $data);   // current page   $currentpage = trim($_request[page]);   // pagination settings   $perpage = 3;   $numpages = ceil(count($dataarray) / $perpage);   if(!$currentpage || $currentpage > $numpages)       $currentpage = 0;   $start = $currentpage * $perpage;   $end = ($currentpage * $perpage) + $perpage;   // extract ones need   foreach($dataarray $key => $val)   {       if($key >= $start && $key < $end)           $pageddata[] = $dataarray[$key];   }  foreach($pageddata $item)       echo '<a href="/'. $item .'/index.php">'. $item .'</a><br>';  if($currentpage > 0 && $currentpage < $numpages)       echo '<a href="?page=' . ($currentpage - 1) . '">« previous page</a><br>';   if($numpages > $currentpage && ($currentpage + 1) < $numpages)       echo '<a href="?page=' . ($currentpage + 1) . '" class="right">next page »</a><br>';  echo '</body></html>'; ?> 

my first problem seems in line 9. change line to:

$currentpage = trim(@$_request[page]); 

but change won't fix error, hide it. needs done line 9 rid page of error?

secondly, fetch data on line 5 in different way. data text file, let's call "items.txt", has entries below, 1 per line.

fun games toys sports fishing pools boats 

please recommend alternate code fetch desired data.

lastly, include links "first page" , "last page" "previous page" , "next page", current code.

i apologize sloppy posting, real appreciative of me understand changes needed produce desired results. thanks.....

problem line 9

$_request[page] has 2 separate problems.

1) page being read name of constant because not quoted. php notices there no constant called page, takes guess meant string page -- if page quoted -- , triggers error notify you. therefore, use $_request['page'] instead.

2) 'page' not key of $_request because data not guaranteed given. therefore, cannot refer $_request['page'] before ensure exists. may done isset($_request['page']).

your final code should this, then.

if (isset($_request['page'])) {     $currentpage = $_request['page']; } else {     $currentpage = 'some default value'; } 

problem data source

the file() function reads lines of file array -- example, fourth value of array fourth line in file. therefore, can set $dataarray $dataarray = file('text.dat');.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -