使用GET,POST和GLOBALS

时间:2018-11-20 04:03:22

标签: php post get

我正在尝试按列的表(作为超链接)对数据表进行排序,而且还要使用<或>按钮进行导航。

<?php
...

if (isset($_POST["next"]) && isset($_POST["start"]))
{
    //force start to be an integer and add 5 to it
    $start = (int)$_POST["start"] + 5;
}
elseif (isset($_POST["prev"]) && isset($_POST["start"]))
{
    //force start to be an integer and remove 5 from it
    $start = (int)$_POST["start"] - 5;
}
else
{
    $start = 0;
}

// if one of hyperlinks in table heading was clicked
if (isset($_GET["sort"]))
{
    $orderByFields = ["TerritoryDescription", "RegionDescription"];
    $GLOBALS['sort'] = $_GET["sort"];
    ...
    SQL here.
}
else
{
...
}


//problem here
// if next button was pressed
if (isset($_POST['next']))
{
    echo 'next';
    if (isset($_GET['sort']))
    {
    echo 'sort';
    //undefined
    //i'm trying to retrive value here.
    echo $GLOBALS['sort'];
    }
}

// if prev button was pressed
elseif (isset($_POST['prev']))
{
    echo 'prev';
}
...

?>

我试图在按下<或>按钮时检索值$ GLOBALS ['sort'],以便按$ GLOBALS ['sort']对SQL结果进行排序。但是,当我尝试从外部访问时,变量未定义。

0 个答案:

没有答案