Re: google style paginating
| From: | Haseeb | Date: | Sat, 23 Aug 2003 20:17:59 +0000 |
| Subject: | Re: google style paginating | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-160487@lists.php.net to get a copy of this message | ||
hi,
i have a simple solutions for paging a large query result into pages.
format your SQL Query like this and it will work
$nTotal_No_Of_Results_Shown_On_A_Page=20;
if (empty($nCurrentPage))
$nCurrentPage=1;
$tablename="tblusers"; // table from where the data is comming from
$fieldtosorton="user_name"; // a field on wich you want to sort the
result returned
$where="user_enabled=1"; // any where clause
$strQuery="SELECT TOP ".$nTotal_No_Of_Results_Shown_On_A_Page." * FROM
$tablename WHERE $fieldtosorton NOT IN (SELECT TOP "
($nTotal_No_Of_Results_Shown_On_A_Page * ($nCurrentPage -1)) ." "
$fieldtosorton." FROM ".$tablename." WHERE $where ORDER BY ".$fieldtosorton.
) ".$where." ORDER BY ".$fieldtosorton;
this query will give you just the result that you want to show on the
current page. all you have to do is maintain $nCurrentPage. if you change
the query slightly you can get the total no of records and when you get
total no of records then you can also get total no of pages.
HTH,
Haseeb
-------Original Message-------
From: Mika Tuupola
Date: Saturday, August 23, 2003 01:00:49 PM
To: Ted Conn
Cc: php-general@lists.php.net
Subject: Re: [PHP] google style paginating
On Thu, 21 Aug 2003, Ted Conn wrote:
> Hi I am new to this newsgroup and I plan on replying to all the posts I
can
> for now... but Id like to start out by asking a question. I am trying to
> paginate my sql results in 10 by 10, which I have been able to do no
> problem. but what I want to do is have the pages layed out in google style
> with (1)(2)(3)(4) etc etc and each one is clickeable that will take you to
> that page. I'll show you the code I am using now for next and back
> buttons...
>
You might want to check Page and Pager_Sliding classes in PEAR:
http://pear.php.net/package-info.php?package=Pager
http://pear.php.net/package-info.php?package=Pager_Sliding
--
Mika Tuupola http://www.appelsiini.net/~tuupola/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php