代码之家  ›  专栏  ›  技术社区  ›  Logan Lee

使用GET、POST和GLOBALS

  •  0
  • Logan Lee  · 技术社区  · 7 年前

    我试图按数据表的列(作为超链接)对数据表进行排序,但也可以使用<或gt;按钮进行导航。

    <?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 回复  |  直到 7 年前