Hulk Smash
Hulk Smash

Reputation: 17

How to display first character in drop down list

I would like to display only the first characters in the drop down list.

For example, I have names like Adam,Harry,James in mysql table. I've created a dropdown list showing the names Adam,Harry etc. But, I want to display only their first characters like A,H,J etc. in the drop down list. Is there any way to do it?

Upvotes: 1

Views: 327

Answers (2)

Amit Rajput
Amit Rajput

Reputation: 2059

Try something like this. I hope this will help.

<option value='" . $row['name'] ."'>" . substr($row['name'], 0, 1) ."</option>

Upvotes: 0

Abhishek Sharma
Abhishek Sharma

Reputation: 6661

use MySQL LEFT :-

LEFT(names , 1)

query like that :-

select LEFT(names , 1) from table 

Upvotes: 3

Related Questions