dongxun4110 2016-02-27 04:06 采纳率: 0%
浏览 35
已采纳

如何在链接中使用查询字符串发送$ _POST

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);
}


?>

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 -->

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.

  • 写回答

1条回答 默认 最新

  • dongzhen7108 2016-02-27 04:10
    关注

    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
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘