2009-06-11 3 views
-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); 
} 

Wie kann ich die ausgewählte Kategorie ID nach der ersten Seite in Paginierung bekommen?Wie kann ich die ausgewählte Kategorie-ID nach der ersten Seite in Paginierung erhalten?

Antwort

0

Bestanden Sie category in der Anfrage? Sie haben uns diese Information nicht gegeben (was ist der Wert von qstr im Javascript?), Aber ich rate nicht.

Sie übergeben es auch direkt in eine SQL-Abfrage, die Sie für die Injektion offen lässt.
Sie sollten mysql_escape_string() verwenden, um das zu beheben.

+0

ich dies mit mysql_escape_string tun hv(), aber nicht funktioniert. Die 2. Seite wird leer. Ich hv nicht Abfrage String als Kategorie in der Javascript übergeben, weil ich in js Programmierung schlecht bin. –

0
  • Post it mit dem Ajax-Aufruf aus und sendet es
  • Bewahren Sie es in einem lokalen JS Variable
  • es Fügen Sie die URL
  • ...
0

Sie scheinen sich bewusst zu sein, dass $_GET['p'] den Wert des Parameters 'p' erhält, der in der Querystring übergeben wird. Nun $_REQUEST['category'] macht das gleiche. (Technisch $_REQUEST überprüft alles in $_POST, $_GET und $_COOKIE).

Wenn Sie also die 'Kategorie' in der Querystring nicht festgelegt haben, dann enthält es nichts in Ihrem Code.

0
  1. Sie sollten hinzufügen? Kategorie = XXX & sid = RAND ... auf Ihre URL
  2. Bessere Nutzung $category = isset($_GET['category']) ? (int)$_GET['category'] : 0;
+0

Ich hv tun mit dem Jahr Code, aber keine Änderungen gefunden.Ich habe den vollständigen Code aktualisiert.Plz sehe wieder meinen Code.Und senden Sie die Antwort an mich. –

0

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

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

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

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

 

 
?> 
 

 
<body> 
 
\t <div> 
 
<div class="headingSec">  \t <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"> 
 
\t \t \t \t <thead class="bgColorSec"> 
 
       \t <th>Registration Id</th> 
 
       \t <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"; 
 
\t 
 
\t $result=mysqli_query($conn,"select * from `student_details` LIMIT $offset,$limit"); 
 
\t 
 
      
 

 
    /* fetch associative array */ 
 
\t 
 
    while($row = mysqli_fetch_array($qry)) { 
 
\t \t 
 
\t \t ?> 
 
\t \t \t 
 
\t \t \t \t <tr> 
 
       \t <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) 
 
\t \t \t \t \t {?> 
 
\t \t \t \t \t \t <td><?php echo "Sucsess"; ?></td> 
 
         <?php 
 
\t \t \t \t \t } 
 
        else{ 
 
\t \t \t \t \t \t ?> 
 
         <td><?php echo "Failed"; ?></td> 
 
         <?php 
 
\t \t \t \t \t }?> 
 
        <?php 
 
        } 
 
\t \t \t \t \t                      
 
\t \t \t \t \t $pre=$page - 1; 
 
\t \t \t \t \t $next=$page + 1; 
 
\t \t \t 
 
\t ?> 
 
\t \t \t \t </tr> 
 
\t \t 
 
\t </table> 
 
    
 
    </div> 
 

 
<br /> 
 
<br /> 
 

 

 
    <div class="pagination"> 
 
    
 
    <?php 
 
for($i=1;$i<=$page_rec;$i++){ 
 
\t 
 
\t 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>

+0

Bitte beschreiben Sie Ihre Lösung und geben Sie nicht nur den Code an. – zuluk

Verwandte Themen