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 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动