这是我的分页程序:
if(isset($_POST['view']))
{
$per_page = 20;
if(isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
$start = $per_page * $page;
$start = $start - $per_page;
if(isset($_GET['seller']) ) {
$seller = $_GET['seller'];
} else {
$seller = ($_POST['seller']);
}
echo $seller."_".$start;
$query = "SELECT Kala.mark ,Kala.sharhe_kala, Kala_forooshande.date From Kala Join Kala_forooshande ON Kala.id_kala=Kala_forooshande.id_kala WHERE Kala_forooshande.id_forooshande=(SELECT id_forooshande From Forooshande where forooshande='". $seller ."') LIMIT $start , $per_page";
$result = mysqli_query($db,$query);
$query2 = "SELECT COUNT(*) as total FROM Kala Join Kala_forooshande ON Kala.id_kala=Kala_forooshande.id_kala WHERE Kala_forooshande.id_forooshande=(SELECT id_forooshande From Forooshande where forooshande='". $seller ."')";
$result2 = mysqli_query($db,$query2);
if ($result->num_rows > 0) {
echo " <form method='post' enctype='multipart/form-data'>
<table class='blueTable'><thead><tr><th>شماره</th><th>شرح کالا</th><th>مارک</th><th>تاریخ</th></tr></thead>";
while ($row = $result->fetch_assoc()) {
$tarikh=gregorian_to_jalali((substr($row["date"],0,4)),(substr($row["date"],5,2)),(substr($row["date"],8,2)));
$j=$start++;
echo "<tr><td>" . $j . "</td><td>" . $row["sharhe_kala"] . "</td><td>" . $row["mark"] . "</td><td>" .$tarikh[0]."-".$tarikh[1]."-".$tarikh[2] . "</td></tr>";
}
echo "</table></form> ";
$total = mysqli_fetch_assoc($result2);
$total_page = (ceil($total['total'] / $per_page));
echo "<table class='pagination'>";
$prev = $page - 1;
if ($page <= 1) {
echo "
<td> << </td>
";
} else {
echo "
<td><a href=\"?page=" . $prev . "\"> << </a></td>
";
}
for ($i = 1; $i <= $total_page; $i++) {
if ($i == $page) {
echo "
<td class='active'>$i</td>";
} else {
echo "
<td><a href=\"?page=" . $i . "&seller=".$seller."\">" . $i . "</a></td>";
}
}
$next = $page + 1;
if ($page >= $total_page) {
echo "
<td>>></td>
";
} else {
echo "
<td><a href=\"?page=$next\"> >></a></td>
";
}
echo "</table>";
}
}
问题是,当用户单击页面2时,<a>
标记发送<a href=\"?page=" . $i . "&seller=".$seller."\">"
来查看页面编号2,但是由于if子句if(isset($_POST['view'])
而无法使用一开始
因此,它仅适用于单击视图按钮的首页。
是否可以在链接中发送按钮值以模拟按钮单击事件?
答案 0 :(得分:1)
根据您对问题的评论:
我只希望在用户单击查看按钮时显示
然后,您需要更多查看按钮。用自己的表单替换链接,这些表单发布服务器端代码期望的值。所以代替这个:
echo "
<td><a href=\"?page=" . $i . "&seller=".$seller."\">" . $i . "</a></td>";
您可能会遇到类似这样的事情:
echo "
<td>
<form method=\"post\">
<input type=\"hidden\" name=\"page\" value=\"" . $i "\" />
<input type=\"hidden\" name=\"seller\" value=\"" . $seller "\" />
<input type=\"submit\" name=\"view\" value=\"" . $i "\" />
</form>
</td>";
如果愿意,可以使用CSS设置按钮样式,使其看起来像链接。诸如Boostrap之类的工具使操作变得非常简单,只需将"btn btn-link"
之类添加到任何可点击元素中即可。
但是,最终,如果您希望链接提交表单,则可以将其创建为表单。