Page 1 of 1

Sort alphabetically ... kind of

Posted: Fri Jan 29, 2010 9:21 am
by sleepydad
I have a database that I would like to allow visitors to my site to search alphabetically. However, due to space on the page, I would like to offer links to sort by names A-G, H-P, Q-Z (Something like that, although the range of the letters is subjective) For example it'll look something like:

Search names:
A-G H-P Q-Z (each of these being a link)

How would I write my query(s) in PHP?

Thanks in advance.

Re: Sort alphabetically ... kind of

Posted: Fri Jan 29, 2010 9:34 am
by AbraCadaver
Something like this:

Code: Select all

SELECT * FROM table_name WHERE LEFT(name_field, 1) BETWEEN 'A' AND 'G'
In php you could use get vars in your link: search.php?start=A&stop=G

Then use the $_GET['start'] and $_GET['stop'] vars in your query.

Re: Sort alphabetically ... kind of

Posted: Fri Jan 29, 2010 9:49 am
by sleepydad
That's what I needed. I had a feeling it would be pretty simple. Thanks much!