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
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
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.