I have 3 (.php) files/pages for a website (in a folder), I have Previous/Next Links displayed on the bottom of each. What php code on the previous/next link, would help me navigate to the next page.
For Example:
Lets say the pages are Page1.php, Page2.php, Page3.php, and I am currently on Page2.php.
If I want to click on the 'Previous' Link, I want Page1.php to be displayed.
If I click on 'Next' then I want Page3.php to be displayed.
I believe this is called 'pagination'?
Previous
Next
I dont know if this is possible. And I hope I have been clear with describing the problem.
Thanks,
babsdoc
Here is the original code @Fred
$images = "jars/"; # Location of small versions
$big = "samp2/"; # Location of big versions (assumed to be a subdir of above)
$cols = 2; # Number of columns to display
if ($handle = opendir($images)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "samp2" && $file != "Thumbs.db") {
$files[] = $file;
}
}
closedir($handle);
}
foreach($files as $file)
{
$pc="Product Code:".substr($file,0,-4);
<a href=\"$images$big$file\" class=\"swap\"><img src=$images$file title=\"title\"
width=\"100\" height=\"100\">
$pc</a></li>";
}
Providing you're going to keep a sane naming convention throughout (ie pageX.php), then the following should suffice. (might not be the ideal solution for you but gives you an idea. Can be put in a function/changes made, etc)
$strCurrentPage = basename($_SERVER['REQUEST_URI']);
$strPattern = '/\d+/';
preg_match($strPattern, $strCurrentPage, $strGetPageNumber); // extract numerical value
//set two new vars to same as page number, increment one and subtract one
$strNextPageNum = $strGetPageNumber[0];
$strPreviousPageNum = $strGetPageNumber[0];
$strNextPageNum++;
$strPreviousPageNum--;
//set full filename with new numbers
$strNextPage = 'page'.$strNextPageNum.'.php';
$strPreviousPage = 'page'.$strPreviousPageNum.'.php';
//if file is found then show link
//next page
if (file_exists($strNextPage))
{
echo '<a href="'.$strNextPage.'">Next Page</a>';
}
else
{
echo "No more pages";
}
//previous page
if (file_exists($strPreviousPage))
{
echo '<a href="'.$strPreviousPage.'">Previous Page</a>';
}
else
{
echo "No previous pages";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.