我是 PHP 新手。我有 2 个 php 文件。
首先是mags.php
<?php
$formurl = "food.php" ;
$viewurl = "try.php" ;
$mytitl = $_POST["magname"];
$cur_page = 1 ;
$page_dir = 'next' ;
$params = http_build_query(array('magname' => $mytitl, 'magpage' => $cur_page, 'pagedir' => $page_dir), '', '&' );
header( "Location: " . $viewurl . "?" . $params);
exit ;
?>
其次是try.php
<?php
$mytitl = $_GET["magname"];
$cur_page = $_GET["magpage"];
$page_dir = $_GET["pagedir"];
$mytitldir = ("./Books/$mytitl/") ;
$myDirectory = opendir($mytitldir);
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName; }
closedir($myDirectory);
$indexCount = count($dirArray);
sort($dirArray);
if ($page_dir == 'next') {
$cur_page++;
if ($cur_page == $indexCount) {
$cur_page = 2;
}
} else {
$cur_page--;
if ($cur_page == 1) {
$cur_page = 3;
}
}
$mag = "$mytitldir$dirArray[$cur_page]" ;
print ("Mag Dir = $mytitldir <br>\n") ;
print("Magazine Page = $mag <br>\n");
print("Page Direction = $page_dir <br>\n");
print("Page # = $cur_page <br>\n");
echo "<img src= \"$mag" . $row['filename'] . "\" alt=\"\" height=\"400\" width=\"400\" /><br />";
?>
<form method="post" action="try.php">
<input type="hidden" name="pagedir" value="next" />
<input type="hidden" name= $cur_page value= 3 />
<input type="hidden" name="magname" value= $mytitl />
<input type="submit" img src="Next_Arrow.png" width="60" height="75" alt="Next" value="Next Page "/>
<td width="60" valign="middle"></td></form>
我的问题是,当用户单击下一步按钮时,我需要加载相同的 try.php。提前致谢