Page 1 of 1

Show specified number of search results per page

Posted: Fri Jun 24, 2005 9:56 am
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.

Posted: Fri Jun 24, 2005 10:00 am
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.

Posted: Fri Jun 24, 2005 10:02 am
by phpScott
pagination is what you are after.
Search this site there is lots of info on it.

Posted: Fri Jun 24, 2005 10:03 am
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;
}