|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
search by initial letter
Hi! I got a database for student listings. I want to have an alphabetic sort of their lastname's first letter. Like i have a link for a, b, c...z. By clicking A - all students whose lastname starts with A will be displayed. Please help...! Thanks so much =)
|
|
#2
|
|||
|
|||
|
RE: search by initial letter
Hi Fairisse,
Probably a million ways to do this, but here are a couple that come to mind most readily. I'm sure the gurus out there will come up with a really slick, less costly way to do it. ;) I'm assuming you have a page with some kind of a menu of links in it (A B C ... Z All). This *could* be dynamically generated from the values in your database (more user friendly...Don't link for X if there are no X last names for example), but we'll leave that as an exercise. ;) These links could be set up to call your PHP script (e.g. fetch_names.php) and the links could be constructed as href="fetch_name.php?letter=A", etc. If you did that, you could grab the search letter from the GET string (e.g. "A", "B", etc.). Your query could then be something like: SELECT * FROM Students WHERE LEFT('Last_Name_Column', 1) = '$get_variable' ORDER BY Last_Name_Column; Not sure about the cost of the LEFT function as opposed to just doing a LIKE: SELECT * FROM Students WHERE Last_Name_Column LIKE "$get_variable%" ORDER BY Last_Name_Column; I'm sure there are more. Be aware of case on your letters...If you aren't forcing entries to be upper or lowercase, you may need to wrap your WHERE condition with UCASE or LCASE to make sure you're comparing apples to apples and not apples to APPLES. Have fun. More MySQL function information can be found at http://www.mysql.com/doc/en/Function_Index.html Hope that helps... |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > search by initial letter |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|