简体   繁体   English

我正在尝试向 url 添加一些不同的 GET 变量

[英]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 中,我有 -

http://localhost?id=2 http://localhost?id=2

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.

相关问题 我正在尝试获取php中的根URL - i am trying to get to the root url in php 我正在尝试使用iframe将全局会话变量与url嵌入 - I am trying to embed global session variables with url using iframe 我正在尝试提交一些表格,但是提交的值仅属于第一个 - I am trying to submit a form out of a few but the value get submitted only belongs to the first one 我正在尝试在htaccess中使用掩码的网址,现在我无法在php中获取搜索查询 - I am trying to use masked url in htaccess and now i am not able to get search queries in php 我无法在 cloudfront 中获得签名的 url,出现致命错误,我正在尝试的代码如下 - I am not able to get signed url in cloudfront, getting fatal error, code I am trying is below 我正在尝试通过网址将包含空格的变量传递到php页面 - I am trying to pass variables which contain spaces through to a php page via a url 我正在尝试将一些 PHP 变量和 Javascript 变量传递到 Javascript window.location.href 中的 url - I am trying to pass some PHP variables and Javascript variable into url in Javascript window.location.href 如何在 php 中将 GET 变量添加到当前 url 的末尾? - How can I add GET variables to end of the current url in php? 我正在尝试将变量加载到数组中 - I am trying to load variables in an array 我试图在页面之间传递变量,但我失败了 - I am trying to pass variables between pages and i am failing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM