$_GET变量在分页代码中未定义



我不熟悉PHP,我遇到了一个为期两周的问题,关于如何在分页代码中生成$_GET$_SESSION变量。情况是:

我有一个来自index.php页面的值,当我点击它时(例如照片/图像),我会使用get获得该值,然后当我将该值回显到Category.php页面时,该值会使用"echo"在BODY页面中正常投影,但我想要的是,当页面加载时,get变量将是我分页代码中的搜索键。但是,当我在分页代码中回显GET变量时,我得到的结果是"UNDEFINED",这意味着该变量没有在分页代码内定义。这是我的页码。哦,是的,我对我的代码做了更改,我很抱歉,但这是我使用$mycat和GET方法的前一个代码。对不起。

<?php
session_start();
$mycat =$_GET['category'];
//PHP code for specific search
$action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
if($action == 'ajax'){
    /* Connect To Database*/
    $dbname = 'ufile';
    $link = mysql_connect("localhost","root","") or die("Couldn't make connection.");
    $db = mysql_select_db($dbname, $link) or die("Couldn't select database");
    $mycat =  htmlspecialchars ($_GET['category']) ? trim($_GET['category']) : ''; //SQL injection protection
    include 'pagination.php'; //include pagination file
    //pagination variables
    $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
    $per_page = 10; //how many records you want to show
    $adjacents  = 4; //gap between pages after number of adjacents
    $offset = ($page - 1) * $per_page;
    echo 'Result: ' .$mycat; //////////THIS IS THE GET VALUE....WHICH TURNS OUT AS UNDEFINED IN VALUE IT SHOULD BE 'PHOTOS/IMAGES, AUDIOS/VIDEOS or COMPRESSED FILES'....PLEASE HELP ME.
    //Count the total number of row in your table*/
    $count_query   = mysql_query("SELECT COUNT(category) AS numrows FROM udocs WHERE category LIKE '%" . $mycat . "%'"); //Count the number of search result here (tagal kitang hinanap dito ka lng pala)
    $row     = mysql_fetch_array($count_query);
    $numrows = $row['numrows'];
    $total_pages = ceil($numrows/$per_page);
    $reload = 'cat_index.php';
    //main query to fetch the data
    $result = mysql_query("SELECT * FROM udocs WHERE category LIKE '%" . $mycat . "%' ORDER BY date_upload LIMIT $offset,$per_page");

    //loop through fetched data
    while($test = mysql_fetch_array($result)){
        $id = $test['file_name'];   
            $fileid=$test['file_path'];
            echo "<div class='content'>";
                echo'<div class="img_content"  ><img src='.$test['file_icon'].' style=height:50px;width:50px;float:left;margin-right:10px;></div>';
                echo"<font  color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Name:   </font><font color='yellowgreen'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['file_name']."</font><br>";
                    echo"<font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Category:   </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['category']."</font></font><font color='skyblue'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>   |   </font><font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Size:   </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['file_size']."</font></font><font color='skyblue'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>   |   </font><font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Credits to:   </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['author']."</font><font color='skyblue'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>   |   </font><font color='black'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>Date Uploaded:   </font><font color='gray'; font size='2px !important' ;font family='Century Gothic, sans-serif' ;letter spacing='2px';>" .$test['date_upload']."</font><br>";
                    echo"<font color='black'; font size='2px !important' ;>Description:". $test['description']. "</font><br>";
                    echo"<a href ='download.php?file_path=$fileid' ><font color='orange' title='$mycat'>Download File</p></a>";
            echo        "</div>";
}
    //BOTTOM
    if ($numrows==0)
    {
    }
    else
    {
        echo paginate($reload, $page, $total_pages, $adjacents);
    }
    //header('Location:index.php');
    //die();
} // end of ajax first condition
else
{
?>
<body>
<?php
 echo 'You are searching for: '.$mycat;
?>
</body>
<?php } ?>

如果$_REQUEST允许您访问参数,但$_GET不允许,请尝试$_POST,这意味着使用的HTTP方法是POST而不是GET。同时检查提交到此脚本的表单/javascript$_REQUEST是一个包罗万象的超全局,包含get和post参数(以及cookie!)。

$_REQUEST

我还建议深入阅读一下HTTP协议,它可以帮助解决这些问题:)

除了Joren刚才评论的内容外,还包括您访问此页面所使用的URL。

正如我在ajax上所理解的那样,你可以获得变量,但当刷新时,你不能对吗?如果im为true,则应将其存储在会话中,然后先查看get/request,然后再查看会话。

放轻松

相关内容

  • 没有找到相关文章

最新更新