I am building a staff directory with little knowledge of what I'm doing and piecing together examples I have found online. Because I am a noob I can't get to where I want to go with this one.
To search by 'Letter' I have a bunch of anchors coded at the page top
e.g. <a href="?by=A">A</a>
Then in the php I have:
if(isset($_GET['by'])){
$letter=$_GET['by'];
// - - - database connection stuff - - -
$sql="SELECT id, f_name, l_name FROM user WHERE f_name LIKE '%" . $letter . "%' OR l_name LIKE '%" . $letter ."%'";
$result=mysql_query($sql);
$numrows=mysql_num_rows($result);
echo "<p>" .$numrows . " results found for " . "<i>" ."'" . $letter . "'". "</>" . "</p>";
// - - - and then the loop that displays it - - -
My Problem is this - If I search for 'A' for example, every name in the database with a letter anywhere in it comes up. I only want names beginning with the letter 'A' to come up.
Thanks for any help you can give me!
I really appreciate it.
If this is a bad way of going about it, let me know that too please and hopefully point me in a brighter direction.