0

hi to all,

i need help from you all...

i need to search in database and to display the match records,
say if search results are 28 in number then i need to show 5records/page (like this records 1-5 in page1, 6-10 in page2.......26-28 in page6) with some options like previous, next, first, last & page nos.


plz someone help by code or links.

thanx in advance...

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by glycerine
1

I would break it down into four parts:

1) run a counter or count query to find the total you have.

2) Store the items in an array

3) Print array values... 5 at a time with a loop.

4) keep track of the page number and which to display using either query strings or session variables.

Also some helpful links:

--http://www.sphider.eu/

--http://www.php-development.ru/php-scripts/search-engine.php

--http://www.ibm.com/developerworks/library/os-php-sphinxsearch/

Edited by redburn: Adding Links to help

0

dear,

if you are having promlem with data base matching you may make you data first criteria and edit its relation properties.

ithink that isn't all but try some times it become solution.

thanks,

fanaxayto.

0

I use the following in my code to search and paginate the results.

/* Setup vars for query. */
	$targetpage = "search.php";//your file name  (the name of this file)
	$limit = 25; //how many items to show per page
	$page = $_GET['paginate'];
	if($page) 
		$start = ($page - 1) * $limit;//first item to display on this page
	else
		$start = 0;

$query = "select * from * where * = * LIMIT $start, $limit"; // EDIT HERE and specify your table and field names for the SQL query

$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);

/* Setup page vars for display. */
	if ($page == 0) $page = 1;//if no page var is given, default to 1.
	$prev = $page - 1;//previous page is page - 1
	$next = $page + 1;//next page is page + 1
	$lastpage = ceil($total_pages/$limit);//lastpage is = total pages / items per page, rounded up.
	$lpm1 = $lastpage - 1;//last page minus 1
	
	/* 
		Now we apply our rules and draw the pagination object. 
		We're actually saving the code to a variable in case we want to draw it more than once.
	*/
	
	$pagination = "";
	if($lastpage > 1)
	{	
		$pagination .= '<div class="pagination">';
		//first button
		if ($page != 1) 
			$pagination.= '<a href="$targetpage">&laquo;  first</a>';
		else
			$pagination.= '<span class="disabled">&laquo; first</span>';
		//previous button
		if ($page > 1) 
			$pagination.= '<a href="$targetpage">&laquo;</a>';
		else
			$pagination.= '<span class="disabled">&laquo;</span>';	
		
		//pages	
		if ($lastpage < 7 + ($adjacents * 2))//not enough pages to bother breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= '<span class="current">$counter</span>';
				else
					$pagination.= '<a href="$targetpage">$counter</a>';					
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
		{
			//close to beginning; only hide later pages
			if($page < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						$pagination.= '<span class="current">$counter</span>';
					else
						$pagination.= '<a href="$targetpage">$counter</a>';					
				}
				$pagination.= "...";
					
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				$pagination.= "...";
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
						$pagination.= '<span class="current">$counter</span>';
					else
						$pagination.= '<a href="$targetpage">$counter</a>';					
				}
				$pagination.= "...";
					
			}
			//close to end; only hide early pages
			else
			{
				$pagination.= "...";
				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
						$pagination.= '<span class="current">$counter</span>';
					else
						$pagination.= '<a href="$targetpage">$counter</a>';					
				}
			}
		}
		
		//next button
		if ($page < $counter - 1) 
			$pagination.= '<a href="$targetpage">&raquo;</a>';
			else
			$pagination.= '<span class="disabled">&raquo;</span>';
		if ($page != $lastpage) 
			$pagination.= '<a href="$targetpage">last &raquo;</a>';
		else
			$pagination.= '<span class="disabled">last &raquo;</span>';
$pagination.= "</div>\n";
	}

Then add

<?=$pagination?>

Where ever you wish for the [<first][1][2][3]....[6][last>] to be displayed.

css

div.pagination {
	color: #1F6B75;
	font: 62.5% Arial, Helvetica, sans-serif;
    padding: 2px;
	text-transform: uppercase;
	clear: both;
	font-weight: bold;
}

div.pagination a {
	padding: 2px 5px 2px 5px;
	margin: 2px;
	color: #1F6B75;
    border: 1px solid #CCC;
    background-color: #FFF;
}
div.pagination a:hover, div.pagination a:active {
	border: 1px solid #5fc0ce;
	background: #fdfdfd url('images/button_bg.png') repeat-x 0 100%;
	color: #000;
}
div.pagination span.current {
	padding: 2px 5px 2px 5px;
	margin: 2px;
	border: 1px solid #5fc0ce;
	font-weight: bold;
	background: #fdfdfd url('images/button_bg_hover.png') repeat-x 0 100%;
	color: #000;
}
div.pagination span.disabled {
	padding: 2px 5px 2px 5px;
	margin: 2px;
	border: 1px solid #EEE;
	color: #DDD;
}

Good luck with making heads or toes with this :D This should go

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.