Welcome to WebmasterWorld Guest from 54.163.49.19

Forum Moderators: open

Message Too Old, No Replies

Retrieve records based on first letter of field

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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 25, 2006
posts:1344
votes: 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?
8:39 am on Feb 1, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0


Try:
SUBSTRING(songTitle,1,1)

A length of 0 will return an empty string.

Or perhaps try:
... WHERE songTitle LIKE '$songIndex%' ...
9:37 am on Feb 1, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 25, 2006
posts:1344
votes: 0


Tried both. Both return empty space where the list is supposed to appear.
9:55 am on Feb 1, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 25, 2006
posts:1344
votes: 0


No wait...

WHERE songTitle LIKE '$songIndex%'

works!

Small typo screwed it all up!

Thanks penders!