Show specified number of search results per page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michealhealy
Forum Newbie
Posts: 1
Joined: Fri Jun 24, 2005 9:43 am

Show specified number of search results per page

Post by michealhealy »

Hi,

I have a search page which is stuctured as follows:

search.php - has the shell (header, leftnav, middlecontent, rightnav, footer) of the page. Within middleContent, I include:

searchA.php;
searchB.php;
searchC.php, each of which query the DB and return search results for a different category.

I haven't really tackled the issue properly yet, but I was wondering if anyone could suggest a good way of showing, say, 6 results from searchA.php on a page, then 6 more on the next etc, followed by 6 from searchB.php and so on.

Thanks for any help, and if you need further clarification, I can post some code.

M.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Modify your SQL by adding following line,

Code: Select all

<?php
$itemPerpage = 6;
$sql = "........LIMIT $currentPage, $itemPerpage";
?>
As you may guess before doing that $currentPage is receieved from user.
If user havent posted yet, it is zero.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

pagination is what you are after.
Search this site there is lots of info on it.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Here is one of them,

Code: Select all

if ($pageNo == "")
	$pageNo = 0;
			
$sqlCount = "select * from gallery";
$resCount = mysql_query($sqlCount);
$itemCount = mysql_num_rows($resCount);
$pageCount = ceil($itemCount/10);
		
$sql = "select * from gallery order by MYID desc limit ".($pageNo*10).", 10";
$res = mysql_query($sql);
while ($info = mysql_fetch_array($res))
{
	$items[count($items)] = $info;
}
Post Reply