hi
i am developing a website where i am using a pagination code .
i want to display the result of the candidate from table record_result on the basis of certain time period given by admin.

that is my code...

<?php
include 'mysql-connect.php';

// how many rows to show per page
$rowsPerPage = 4;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

				
$order = "SELECT * FROM result_record WHERE ex_date>='$var' AND ex_date<='$var1'".
" LIMIT $offset, $rowsPerPage";
				
$result = mysql_query($order);	

				
while($data = mysql_fetch_row($result))
{
  echo("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[4]</td><td>$data[3]</td><td>$data[5]</td><td>$data[6]</td></tr>");
}
?>
<?php
$query1   = "SELECT COUNT(*) AS numrows FROM result_record";
$result1  = mysql_query($query1) or die('Error, query failed');
$row1     = mysql_fetch_array($result1, MYSQL_ASSOC);
$numrows = $row1['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];

// ... still more code coming
?>

 <?php

if ($pageNum > 1)
{
   $page  = $pageNum - 1;
   $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";

   $first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
   $prev  = '&nbsp;'; // we're on page one, don't print previous link
   $first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)
{
   $page = $pageNum + 1;
   $next = " <a href=\"$self?page=$page\">[Next]</a> ";

   $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
   $next = '&nbsp;'; // we're on the last page, don't print next link
   $last = '&nbsp;'; // nor the last page link
}
echo $first . $prev .
" Showing page $pageNum of $maxPage pages " . $next . $last;


?>

the problem is it is not give the desired output.
plz any one help me that what is the problem????
or how to use limit with where clause...

<?php
				//paging settings
				// how many rows to show per page
				$rowsPerPage =3;
				//query
				$pagingqry = " YOUR QUERY ";
				//extra get variables
				$gets = "?1=1";
				include("includes/paging.php"); 
				?>

* Here YOUR QUERY contains your query from which you want to get result

* you can see another thing like $gets = "?1=1";

Here you can pass your search criteria...... this will b work your extra argument.......

your paging file is like below :

<?
			
			// by default we show first page
			$pageNum = 1;
			
			// if $_GET['page'] defined, use it as page number
			if(isset($_GET['page']))
			{
				$pageNum = $_GET['page'];
			}
			
			// counting the offset
			$offset = ($pageNum - 1) * $rowsPerPage;
			
			$limit = " LIMIT $offset, $rowsPerPage";
			
			// how many rows we have in database
			$result  = mysql_query($pagingqry) or die('Error, query failed');
			$numrows     = mysql_num_rows($result);
			
			// how many pages we have when using paging?
			$maxPage = ceil($numrows/$rowsPerPage);
			
			// print the link to access each page
			$self = $_SERVER['PHP_SELF'].$gets;
			$nav  = '';
			
			for($page = 1; $page <= $maxPage; $page++)
			{
			   if ($page == $pageNum)
			   {
				  $nav .= "<span class='text_2'> $page </span>"; // no need to create a link to current page
			   }
			   else
			   {
				  $nav .= " <a class='link_2' href=\"$self&page=$page\">$page</a> ";
			   } 
			}
			
			// creating previous and next link
			// plus the link to go straight to
			// the first and last page
			
			if ($pageNum > 1)
			{
			   $page  = $pageNum - 1;
			   $prev  = " <a class='link_2' href=\"$self&page=$page\">[Prev]</a> ";
			
			   $first = " <a class='link_2' href=\"$self&page=1\">[First]</a> ";
			} 
			else
			{
			   $prev  = '&nbsp;'; // we're on page one, don't print previous link
			   $first = '&nbsp;'; // nor the first page link
			}
			
			if ($pageNum < $maxPage)
			{
			   $page = $pageNum + 1;
			   $next = " <a class='link_2' href=\"$self&page=$page\">[Next]</a> ";
			
			   $last = " <a class='link_2' href=\"$self&page=$maxPage\">[Page]</a> ";
			} 
			else
			{
			   $next = '&nbsp;'; // we're on the last page, don't print next link
			   $last = '&nbsp;'; // nor the last page link
			}
			
			
			

function ShowPaging($first , $prev , $nav , $next , $last)
{
	// print the navigation link
	$str = "<table cellpadding=0 cellspacing=0 width=70% border=0><tr>";	
	
	
	echo $first . $prev . $nav . $next . $last;
	
	$str .=	"</tr></table>";
}

?>

* where u want to show paging just call function below:
<?php echo ShowPaging($first , $prev , $nav , $next , $last);?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.