Jump to content

detect first letter of a word


jwk811

Recommended Posts

i have a list of words and they will be categorized by the first letter.. like the person will click a or b or c etc. and all the words with that letter will come up.. for the first part i will need to know how to be able to see what the first letter of the word is so i can do that.. next i will need to figure out how i can take only the words starting with that letter from the database to be displayed.. i need help with both but either will be great! thanks for any help on this!
Link to comment
https://forums.phpfreaks.com/topic/31009-detect-first-letter-of-a-word/
Share on other sites

Well you can always get the 1st letter of a string just like you'd get the 1st element of an array:
$a = "string";

echo $a[0];

that would output s

but to search for all records that start with a particular letter you could use a like in your query:

select * from table_name where column like 'a%'

that should get all the records from column that start with a
[quote author=mlin link=topic=119009.msg486802#msg486802 date=1166388321]
select * from table_name where column like 'a%'
[/quote]

I agree, best to solve as many data issues at the sql script instead of sorting this out in PHP, so the above SQL query would be correct.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.