我不熟悉PHP,我在如何在我的分页代码中制作$_GET
或$_SESSION
变量时遇到了2周的问题。情况是:
我有一个来自index.php
页面的值,当我点击它时(例如照片/图像)我使用GET获取值,然后当我将值回显到我的Category.php
页面时,值使用'echo'在我的BODY页面中投影正常,但我想要的是当页面加载时,GET变量将成为我的分页代码中的searchkey。但是当我在我的分页代码中回显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 } ?>
答案 0 :(得分:2)
如果$ _REQUEST允许您访问参数,但$ _GET不会,请尝试$ _POST,这意味着使用的HTTP方法是POST而不是GET。检查提交到此脚本的表单/ javascript。 $ _REQUEST是一个捕获所有超级全局,包含get和post参数(以及cookie!)。
我还建议深入研究一下HTTP协议,它可以解决这些问题:)
除了Joren刚评论的内容外,还要包含您用来访问此页面的网址。
答案 1 :(得分:-1)
正如我在ajax上所理解的那样你可以变量,但是当你刷新时你不能正确吗?如果我是真的,你应该把它存储在会话上,然后先看看get / request然后再查看会话。
放轻松