如何在链接中发送带有查询字符串的$ _POST [英] How Can I send $_POST with query string in a link

查看:141
本文介绍了如何在链接中发送带有查询字符串的$ _POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是php代码,用于检查是否发布了表单(在同一页面上)并根据$ _POST数组获取结果(如果已发布)或从数据库返回所有结果.这还会设置$ total变量,该变量包含稍后用于分页的number_of_pages

This is php code which checks if form(on same page) is posted and gets the result depending upon $_POST array if it is posted or returns all results from data base. this also sets $total variable containing number_of_pages later used for pagination

if(!isset($_POST['search']))
{

$id = (isset($_GET['id']) ? $_GET['id'].'0' : 10);
$id = $id-10;
$query  = "select SQL_CALC_FOUND_ROWS * from feedbacks order by Date desc limit $id, 10 ";
}
else if (!empty($_POST['from']))
{

$timstmp = strtotime($_POST['from']);
$dt = date("Y-m-d H:i:s", $timstmp);

$id = (isset($_GET['id']) ? $_GET['id'].'0' : 10);
$id = $id-10;
$query = "SELECT SQL_CALC_FOUND_ROWS * FROM `feedbacks` WHERE `Date` >= \"$dt\" order by Date desc limit $id, 10 ";
}
else if (!empty($_POST['name']))
 {

$name = '%'.$_POST['name'].'%';

 $id = (isset($_GET['id']) ? $_GET['id'].'0' : 10);
$id = $id-10;
$query = "SELECT SQL_CALC_FOUND_ROWS * FROM `feedbacks` WHERE `name` LIKE  '$name' order by Date desc limit $id, 10 ";
}
 $result= mysqli_query($connection, $query);

$r =  mysqli_fetch_array(mysqli_query($connection, 'SELECT FOUND_ROWS()'));
$total = ceil($r['FOUND_ROWS()']/10);

$feedbacks = array(); 
for ($i = 0;$row= mysqli_fetch_assoc($result); $i++)
{
    $feedbacks[$i] = new FeedBack($row);
}


?>

这些是根据页面总数自动生​​成的html链接,而页面总数是根据数据库的结果而计算的

These are the html links that are automatically generated depending upon the total number of pages which is calculated depending upon results from data base

<?php
if ($total>1)
{ ?> <div class="pagging">
<?php     for( $i=$total; $i>=1; $i--)
{ ?>

                        <div class="right">
                            <a id="pagination" href="index.php?id=<?php echo $i; ?>"><?php echo $i; ?></a>
                        </div>

                    <?php } ?>
                     </div>
            <?php       } ?>
                </div>
                <!-- Table -->

在此页面上,我正在实施过滤器.用户以表格形式输入数据并按搜索,以便根据$ _POST数组加载不同的结果,并修改包含num_of_pages的变量$ total,因为php代码的第一个块显示了第一页,现在第一页显示了使用偏移量的数据库的第1个10个结果0或ofset = IDX10-10(如果设置了id),但问题是它仅适用于默认结果,即,当显示所有结果且未应用过滤器时,但当用户搜索经过过滤的第1个结果时,将显示10个过滤结果,但当用户单击下一页它不起作用,因为$ _POST未设置,已由php如果上述php代码中的条件进行了检查.所以我的问题是我该如何发送$ _POST []和ID来使其正常工作.任何帮助,将不胜感激.谢谢.

On this page I'm implementing filters. User input data in the form and press search so depending upon the $_POST array the different results are loaded and variable $total containing num_of_pages is modified as the 1st block of php code shows now the first page displays 1st 10 results from data base using offset 0 or ofset = IDX10-10 if id is set but problem is that it only works for default results i.e when all results are displayed and filter is not applied but when user searches through a filtered 1st 10 filtered results are displayed but when user clicks the next page it does not work because $_POST is unset which was checked by the php If conditions in above php code. so my question is how can i send $_POST[] along with the id to make it work. Any help would be appreciated. Thanks.

推荐答案

您无法通过链接发送POST变量.您需要使用GET.

You can't send POST variables through a link. You need to use GET.

<a href="some_page.php?<?=http_build_query($assc_array);?>">Link</a>
//the link will reflect some_page.php?name1=value1&name2=value2...etc

在PHP方面,请使用$ _GET或$ _REQUEST变量,而不是$ _POST.

On the PHP side use the $_GET or $_REQUEST variable, instead of $_POST.

这篇关于如何在链接中发送带有查询字符串的$ _POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆