Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old February 6th, 2003, 12:39 AM
fairisse fairisse is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Philippines
Posts: 2 fairisse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 =)

Reply With Quote
  #2  
Old February 6th, 2003, 03:58 AM
NetproHosting NetproHosting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apex, NC, USA
Posts: 31 NetproHosting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to NetproHosting
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...

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > search by initial letter


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway