[英]I am trying to add a few different GET variables to the url
I'm currently working on php pagination and I manage to get the code working... my problem now is that each time I click on the NEXT or PREVIOUS button the variable in the url will be no more..我目前正在处理 php 分页,我设法让代码正常工作......我现在的问题是每次我点击 NEXT 或 PREVIOUS 按钮时,url 中的变量将不再存在..
please how do I make the variables already in the url stay fixed why the new pagination variables are added to the url...请问如何使 url 中已有的变量保持不变,为什么将新的分页变量添加到 url 中...
My url我的网址
www.example.com/profile.php?id=2 www.example.com/profile.php?id=2
When a click on the pagination previous or next button my url will look like当单击分页上一个或下一个按钮时,我的网址将如下所示
www.example.com/profile.php?pageno=4 www.example.com/profile.php?pageno=4
My problem is how do I make the id=2 not leave even as I continue to click on the pagination button我的问题是如何让 id=2 不离开,即使我继续点击分页按钮
www.example.com/profile.php?id=2&pageno=3 www.example.com/profile.php?id=2&pageno=3
www.example.com/profile.php?id=2&pageno=4 www.example.com/profile.php?id=2&pageno=4
www.example.com/profile.php?id=2&pageno=5 www.example.com/profile.php?id=2&pageno=5
Pagination code.... please help me分页码....请帮帮我
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 10;
$offset = ($pageno-1) * $no_of_records_per_page;
$conn=mysqli_connect("localhost","skyworld1_sky","uromiUROMI914@#","skyworld1_sky");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
$total_pages_sql = "SELECT COUNT(*) FROM phonegap2";
$result = mysqli_query($conn,$total_pages_sql);
$total_rows = mysqli_fetch_array($result)[0];
$total_pages = ceil($total_rows / $no_of_records_per_page);
$sql = "SELECT * FROM phonegap2 LIMIT $offset, $no_of_records_per_page";
$res_data = mysqli_query($conn,$sql);
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>email</th>";
echo "<th>fullname</th>";
echo "<th>country</th>";
echo "<th></th></tr>";
while($row = mysqli_fetch_array($res_data)){
//here goes the data
echo "<tr><td>";
echo $row['email'];
echo "</td><td>";
echo $row['fullname'];
echo "</td><td>";
echo $row['country'];
echo "</td><td>";
echo " <input type='submit' value='BUY'>";
echo "</td><tr>";
}
echo "</table>";
mysqli_close($conn);
?>
<ul align="center" class="pagination">
<li><a href="?pageno=1">First</a></li>
<li class="<?php if($pageno <= 1){ echo 'disabled'; } ?>">
<a href="<?php if($pageno <= 1){ echo '#'; } else { echo "?pageno=".($pageno - 1); } ?>">Prev</a>
</li>
<li class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>">
<a href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?pageno=".($pageno + 1); } ?>">Next</a>
</li>
<li><a href="?pageno=<?php echo $total_pages; ?>">Last</a></li>
</ul>
Problem问题
You need the ID field to show in the URL when a user clicks the previous or next links.当用户单击上一个或下一个链接时,您需要在 URL 中显示 ID 字段。
Solution解决方案
If you have an ID as a GET param you can simply pull it out of the URL and add it to your links in the page.如果您有一个 ID 作为 GET 参数,您可以简单地将其从 URL 中拉出并将其添加到页面中的链接中。
<a href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?id=".$_GET['id']."&pageno=".($pageno + 1); } ?>">Next</a>
Example例子
In my URL on page load I have -在页面加载的 URL 中,我有 -
Then in the PHP page -然后在 PHP 页面中 -
<?php
$total_pages = 100;
$pageno = 3;
?>
<a href="<?php echo "?id=".$_GET['id']."&pageno=".($pageno + 1); ?>">Next</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.