homepage Welcome to WebmasterWorld Guest from 54.196.24.103
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Retrieve records based on first letter of field
andrewshim




msg:4412982
 7:26 am on Feb 1, 2012 (gmt 0)

Hi... I have a table of Kids Church songs containing approximately 200 songs. I'd like to be able to retrieve records alphabetically using the first letter of the songTitle, based on the alphabet in the URL string...

Example : www[dot]examplesite[dot]com/song.php?songIndex=A

I can't seem to get the Select statement correct.

Select * from table where substring(songTitle, 1, 0) = $songIndex order by songTitle


I'm sure it's wrong, but can someone help please?

 

penders




msg:4412992
 8:39 am on Feb 1, 2012 (gmt 0)

Try:
SUBSTRING(songTitle,1,
1)

A length of 0 will return an empty string.

Or perhaps try:
... WHERE songTitle LIKE '$songIndex%' ...

andrewshim




msg:4413007
 9:37 am on Feb 1, 2012 (gmt 0)

Tried both. Both return empty space where the list is supposed to appear.

andrewshim




msg:4413013
 9:55 am on Feb 1, 2012 (gmt 0)

No wait...

WHERE songTitle LIKE '$songIndex%'

works!

Small typo screwed it all up!

Thanks penders!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved