你好我有这个表格:
<form method="get">
<input type="number" name="page=home&paginH">
<input type="submit">
</form>
而且我的代码中有一个分页......所以我想在我的网站中放置一个字段,就像上面的表格一样,当用户在字段中写一个数字并提交它时,必须将他重定向到用户写的页面。我的问题是这样的......我在我的 URL 中获取的结果是http://example.com/index.php?page%3Dhome%26paginH=2最后的数字“2”是用户提交的数字. 问题是 URL 更改但页面仍然相同。我已经搜索了很多,但我找不到解决方案。提前致谢!
是的,我很抱歉!
这是我的 php:
<?php
$per_page = 1;
//Ayto einai to apotelesma p 8a vgalei sto index(arxiko h home) ola ta post mazi.
$pages_query = mysql_query("SELECT COUNT(`ID`) FROM `posts`") or die(mysql_error());
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
//$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
if (isset($_GET['paginH'])) {
$page = (int)$_GET['paginH'];
} else {
$page = 1;
}
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT * FROM `posts` ORDER BY `Date` DESC LIMIT $start, $per_page") or die(mysql_error());
if(mysql_num_rows($query) == 0) {
echo "<tr><td colspan=\"3\">No Posts Were Found</td></tr>";
} else {
while($post = mysql_fetch_array($query)) {
$article_id=$post["ID"];
$link = "admin_login_bg/includes/article_result_readmore_img.php";
$var = "article_id";
$id = $post['ID'];
$date = $post['Date'];
$image = $post['Image_home'];
echo "<div class='perigrama'><div class='titlos'><h2><a href='admin_login_bg/includes/article_result_readmore_img.php?article_id=" . $article_id . "'><span>" . $post['Title'] . "</span></a></h2></div><div class='infos'><p>Posted by <a href='#'><span>" . $post['Author'] . "</span></a> on ". $date . " | <a href='admin_login_bg/includes/article_result_readmore_img.php?article_id=" . $article_id . "'><span>Full article</span></a></p></div><tr><td><div class='image'><img src='". $image ."' width='540' height='300'></div></td></tr><div class='content'><p>" . truncate($post['Content'],$link,$var,$id) . "</p></div><div class='more'><p><a href='admin_login_bg/includes/article_result_readmore_img.php?article_id=" . $article_id . "'><span>Read more</span></a></p></div></div>";
}
}
echo '<div class="pagination"><ul><li>';
//$first = 1;
//if ($pages >= 1) {
// echo '<a href="?page=home&paginH='.$first.'">First</a> ';
//}
$prev = ($page - 1);
if ($page > 1) {
echo '<a class="prevnext paginH" href="?page=home&paginH='.$prev.'"><span class="velakiaPrevNext"><<</span> Previous</a> ';
}
$first = 1;
if ($page > 3) {
if ($pages >= 1) {
echo '<a href="?page=home&paginH='.$first.'">1</a> ';
}
}
if ($page > 3) {
echo ' <span>...</span> ';
}
if ($pages >= 1 && $page <= $pages) {
//for ($x=1; $x<=$pages; $x++) {
//for ($x = $page + 0; $x <= min($page + 3, $pages); $x++) {
for($x = max(1, $page - 2); $x <= min($page + 2, $pages); $x++) {
//for ($x = $page + 0; $x <= max($page + 3, $pages); $x++) {
echo ($x == $page) ? '<strong><a class="currentpage" href="?page=home&paginH='.$x.'">'.$x.'</a></strong> ' : '<a href="?page=home&paginH='.$x.'">'.$x.'</a> ';
//}
}
}
$p = ($pages - 3);
if ($page <= $p) {
echo ' <span>...</span> ';
}
$last = $pages;
if ($page <= $p) {
if ($pages >= 1) {
echo '<a href="?page=home&paginH='.$last.'">'.$pages.'</a> ';
}
}
$next = ($page + 1);
if ($page < $pages) {
echo '<a class="prevnext" href="?page=home&paginH='.$next.'">Next <span class="velakiaPrevNext">>></span></a> ';
}
//if ($pages >= 1) {
// echo '<a href="?page=home&paginH='.$last.'">Last</a> ';
//}
echo '</li></ul></div>';
?>