我有3个(.php)文件/页面用于网站(在文件夹中),我有每个底部显示的上一个/下一个链接。上一个/下一个链接上的php代码可以帮助我导航到下一页。
例如:
让我们说这些页面是Page1.php,Page2.php,Page3.php,我目前在Page2.php上。
如果我想点击“上一个”链接,我希望显示Page1.php。
如果我点击“下一步”,那么我希望显示Page3.php。
我认为这被称为'分页'?
上
下一步
我不知道这是否可行。我希望我已经清楚地描述了这个问题。
谢谢,
babsdoc
答案 0 :(得分:0)
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>";
}
答案 1 :(得分:0)
如果您要在整个过程中保持一个合理的命名约定(即pageX.php),那么以下内容就足够了。 (可能不是你理想的解决方案,但会给你一个想法。可以放入一个函数/做出更改等)
$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";
}