【发布时间】:2013-12-26 01:10:41
【问题描述】:
我对 PHP 不熟悉,并且在我的分页代码中如何创建 $_GET 或 $_SESSION 变量时遇到了 2 周的问题。情况是:
我有一个来自index.php 页面的值,当我单击它(例如照片/图像)时,我使用 GET 获取该值,然后当我将该值回显到我的Category.php 页面时,该值在我的 BODY 页面使用“echo”,但我想要的是当页面加载时,GET 变量将是我的分页代码中的搜索键。但是当我在我的分页代码中回显 GET 变量时,我得到了这个结果“未定义”,这意味着该变量没有在我的分页代码中定义。这是我的分页。哦,是的,我对我的代码进行了更改,我很抱歉,但这是我之前使用 $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 } ?>
【问题讨论】:
-
请求此文件的 URL 看起来如何?
-
看不到 whare
$mycat被传递到paginate(),如果您尝试在paginate函数中访问$mycat将超出范围 -
回显输出变为未定义投影到页面...这意味着变量未被读取..但是当我用正文回显它时...我得到的值为照片/图像。 ..我希望这个值出现在我上面的查询中......
-
charlietfl 我只是放置它,但它没有读取它...
-
在我的 index.php 中我得到这样的值
- 照片和图像"; @Joren
标签: php jquery mysql ajax pagination