-1
<?php
include "includes/connection.php";

        //$id=$_REQUEST['category'];
        //$catid=mysql_escape_string($id);

$catid = isset($_GET['category']) ? (int)$_GET['category'] : 0;

$recordsPerPage =4;
# 0
// //default startup page
$pageNum = 1;

if(isset($_GET['p']))
{
$pageNum = $_GET['p'];
settype($pageNum, 'integer');
}
$offset = ($pageNum - 1) * $recordsPerPage;
//set the number of columns
$columns = 1;


//set the number of columns
$columns = 1;

$query = "SELECT temp_id, temp_img, temp_header, temp_resize, temp_small, temp_name, temp_type, cat_id, col_id, artist_id FROM `templates` where   cat_id = '{$catid}' ORDER BY `temp_id` DESC LIMIT $offset, $recordsPerPage";
$result = mysql_query($query);
//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<div>";
//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
while($row = mysql_fetch_array($result)){
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<div class='template'>";
}
echo ...........my data(s).
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
echo "</div>";
}
}
}
echo "</div>";
//}
?>  


    <div class="pagination">
    <?
    $query = "SELECT COUNT( temp_id ) AS  `temp_date` FROM `templates` where  cat_id ='{$catid}'";

$result = mysql_query($query) or die('Mysql Err. 2');
$row = mysql_fetch_assoc($result);
$numrows = $row['temp_date'];
//$numrows = mysql_num_rows($result);

$self = $_SERVER['PHP_SELF'];

$maxPage = ceil($numrows/$recordsPerPage);

$nav = '';

for($page = 1; $page <= $maxPage; $page++)
{ if ($page == $pageNum)
{
$nav .= "<span class=\"pegination-selected\">$page</span>";
}
else
{
$nav .= "<aa class=\"pegination\" hreeef=\"javascript:htmlData('$self','p=$page')\">$page</a>";
}
}
if ($pageNum > 1)
{

$page = $pageNum - 1;
$prev = "<aa class=\"pagination\" hreeef=\"javascript:htmlData('$self','p=$page')\"><strong><imgee src=\"images/previous.gif\" alt=\"previous\" width=\"5\" height=\"10\" border=\"0\"/></strong></a>";

$first = "<aa class=\"pagination\" hreeef=\"javascript:htmlData('$self','p=1')\"><strong><imgee src=\"images/previous1.gif\" alt=\"first\" width=\"7\" height=\"10\" border=\"0\" /></strong></a>";
}
else
{
$prev = '<strong> </strong>';
$first = '<strong> </strong>';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = "<aa  hreeef=\"javascript:htmlData('$self','p=$page')\"> <strong> <imgee src=\"images/next.gif\" alt=\"next\ width=\"5\" height=\"10\" border=\"0\" /></strong></a>";
$last = "<a class=\"pagination\" hreeef=\"javascript:htmlData('$self','p=$maxPage')\"> <strong> <imgee src=\"images/next1.gif\" alt=\"next\" border=\"0\" width=\"7\" height=\"10\" /></strong></a>";
}

else
{
$next = '<strong> </strong>';
$last = '<strong> </strong>';
}
echo "<div class=\"pagination\"> $first $prev <span class=\"pagination-selected\">$nav </span> $next $last </div>";

?>              

Here my ajax code:

function GetXmlHttpObject(handler)
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtResult").innerHTML=xmlHttp.responseText
}
else
{
//alert(xmlHttp.status);
}
}

function htmlData(url, qStr)
{
if (url.length==0)
{
document.getElementById("txtResult").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}

url=url+"?"+qStr;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true) ;
xmlHttp.send(null);
}

ページネーションの最初のページの後に選択したカテゴリ ID を取得するにはどうすればよいですか?

4

5 に答える 5

0

リクエストに合格しますcategoryか?あなたは私たちにその情報を提供していません ( qstrjavascript の値は何ですか?) が、そうではないと思います。

また、それを直接 SQL クエリに渡しているため、インジェクションの危険性があります。それを修正するために
使用する必要があります。mysql_escape_string()

于 2009-06-11T11:25:24.090 に答える
0
  • AJAX 呼び出しで投稿して返す
  • ローカル JS 変数に格納する
  • URLに追加します
  • ...
于 2009-06-11T11:31:35.633 に答える
0

$_GET['p']クエリ文字列で渡された「p」パラメーターの値を取得していることに気付いているようです。まあ$_REQUEST['category']、同じことをしています。( 、およびのすべてを技術的$_REQUESTにチェックしました)。$_POST$_GET$_COOKIE

したがって、クエリ文字列に「カテゴリ」を設定していない場合、コードには何も含まれません。

于 2009-06-11T11:31:36.477 に答える
0
  1. 追加する必要がありますか?category=XXX &sid=RAND... をあなたの URL に
  2. より良い使用$category = isset($_GET['category']) ? (int)$_GET['category'] : 0;
于 2009-06-11T11:46:22.120 に答える