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.
Sort alphabetically ... kind of
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Sort alphabetically ... kind of
Something like this:
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.
Code: Select all
SELECT * FROM table_name WHERE LEFT(name_field, 1) BETWEEN 'A' AND 'G'Then use the $_GET['start'] and $_GET['stop'] vars in your query.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Sort alphabetically ... kind of
That's what I needed. I had a feeling it would be pretty simple. Thanks much!