How to check if a variable starts with a certain letter?

I have a dropdown list in a form which is populated via a database.
The problem I have is that the current call is pulling back all of the distinct vlues from one column.
I need to work out a way to combine these into sections in the resulting drop down menu.

For example the current drop down is pulling back values such as the list below:

A150
A160
A170
A180

What I need is a code which will combine all of these values into one signle drop down option of for example “A Section”

Can anyone give me some pointers as to how I can do this?
there is a common pattern as in if the option starts with the letter A I want it to show “A Section” instead of all of the individual options.

Any help much appreciated.

Thanks in advance.

Well, I’ve read this a few times and I still do not understand the question.

How about you give us a “before” and “after”. The problem you have and the expected outcome illustrated with some code, maybe?

I think what you want is the first letter of all database values, but each letter only once?
If so, change your query to something like this


SELECT DISTINCT
   LEFT(columnname, 1) AS letter
FROM tablename
WHERE
  ....


Pull Row
Set $holder = substr($row[field],0,1)
echo <select ....>
while (Pull row) {
  if(substr($row[field],0,1) != $holder) {
       echo "</select><select .......>"
       $holder = substr($row[field],0,1);
  }
  echo <option ....>.....</option>
}
echo </select>