-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
  • 使用 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... 到您的网址
  2. 更好的使用$category = isset($_GET['category']) ? (int)$_GET['category'] : 0;
于 2009-06-11T11:46:22.120 回答
0

category在请求中通过了吗?您没有向我们提供该信息(qstrjavascript 中的值是什么?),但我猜不是。

您还将它直接传递到 SQL 查询中,这使您可以进行注入。
你应该用它mysql_escape_string()来解决这个问题。

于 2009-06-11T11:25:24.090 回答
0

<?php
include ('database connection file ');

?>
 **and this is my index.php**
<?php

if(isset($_GET['page']))
{
	$page=$_GET['page'];
	$offset=$limit * ($page - 1);
    
    
}
else{
	$page=1;
	$offset=0;
	
}

if($page==0 || $page > $page_rec){
	header('location:index.php?page=1');
}


?>

<body>
	<div>
<div class="headingSec">    	<h1 align="center">Welcome Admin<a href="adminlogout.php">Logout</a></h1>
        <p align="center">Manage your student database here.</p></div>
        <table  class="trBgColr">
				<thead class="bgColorSec">
                	<th>Registration Id</th>
                	<th>Image</th>
                    <th>Signature</th>
                    <th>Name</th>
                    <th>Father's Name</th>
                    <th>City</th>
                    <th>Registration Category</th>
                    <th>Phone Number</th>
                    <th>Mobile Number</th>
                    <th>Status</th>
                    <th>
                </thead>
        <?php
        //$getstudentdetails = "select * from student_details";
	
	$result=mysqli_query($conn,"select * from `student_details` LIMIT $offset,$limit");
	
         

    /* fetch associative array */
	
    while($row = mysqli_fetch_array($qry)) {
		
		?>
			
				<tr>
                	<td><?php echo $row["registration_number"]; ?>
                    <td><?php echo $row["Name"]; ?></td>
                    <td><?php echo $row["Father_Name"]; ?></td>
                    <td><?php echo $row["City"]; ?></td>
                    <td><?php echo $row["Registration_Category"]; ?></td>
                    <td><?php echo $row["Phone_Number"]; ?></td>
                    <td><?php echo $row["Mobile_Number"]; ?></td>
                    <?php if($row['payment_status']==1)
					{?>
						<td><?php echo "Sucsess"; ?></td>
                        <?php
					}
                    else{
						?>
                        <td><?php echo "Failed"; ?></td>
                        <?php
					}?>
                    <?php
                    }   
					                                                                                     
					$pre=$page - 1;
					$next=$page + 1;
			
	?>
				</tr>
		
	</table>
   
    </div>

<br />
<br />


    <div class="pagination">
  
    <?php
for($i=1;$i<=$page_rec;$i++){
	
	continue;
 ?>
  <a href="?page=<?php echo $i?>"><?php  $i;?> </a>
  <?php } ?>

<a href="?page=<?php echo $pre ;?>">Previous&laquo;</a>

<a href="?page=<?php echo $next ;?>">Next&raquo;</a>

于 2017-05-12T13:31:38.350 回答