The SQL statement would be something like this:
SELECT name FROM tableName WHERE name LIKE 'B%';
SQL can do some amazing things. I encourage you to read some tuturials on the subject.
As far as the PHP portion of the question goes, I'd suggest reading one of the many tutorials on the subject. It's very difficult to know what level of detail you require.