Re: Alphabetical pagination

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 4:30 PM +0100 7/15/09, Ashley Sheridan wrote:
On Wednesday 15 July 2009 16:21:22 tedd wrote:
 At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
 >I am trying to make a page that displays a-z like a b c d e etc as links
 >then when you click open one it reloads itself and shows only the query
 >results that go with that letter...i'm not getting it....I get a page that
 >says ARRAY over and over...
 >
 >What I have so far:

 -snip-

 Why not have MySQL sort the data instead of using php?

 For example (from memory -- use with caution)

 SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1

 Then just change the offset to go up and down the list.

 Cheers,

 tedd
 --
 -------
 http://sperling.com  http://ancientstones.com  http://earthstones.com

You could do what Tedd suggested, but use MySQL to actually limit the results
it returns you by using a like clause, i.e. WHERE `somefield` LIKE 'a%'.

*ducks to avoid people throwing things at him. I know it's slow!*

--
Thanks,
Ash


Ash:

My solution on this is simply to sort all the names and then pull them out one by one depending upon where they appear in the sort. I don't really see the need for LIKE to do this unless the user is entering a guess. In such case, then you want to provide them with your best fit.

Here's an example of both:

http://php1.net/a/edit-db-demo/index.php

The user can step through the database, which is initially sorted on last name. If the user picks to sort on email, then the sort is done as per email. In both cases, the data is stepped through sequentially (Alphabetical pagination) by using an offset and limit combination.

However, if the user clicks on an alphabetical tab, then I use a LIKE to place them (their pagination) at the position of that sort at that character. That's where a LIKE would work well.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux