mishasoni Posted October 9, 2008 Share Posted October 9, 2008 Hi, I have a MySQL db with a table that has a field called "NameLast". I am trying to figure out how to filter the results using a URL variable based on the first letter of the records. eg, http://mydomain.com/page.php?firstletter=A so then all records with the first letter of "A" in the NameLast column gets displayed. This seems like it should be simple enough but I am a PHP newbie and would welcome a bit of assistance. Thanks. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 9, 2008 Share Posted October 9, 2008 You could just do $firstletter = mysql_real_escape_string($_GET['firstletter']); mysql_query("SELECT whatever FROM wherever WHERE NameLast LIKE '{$firstletter}%'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 9, 2008 Share Posted October 9, 2008 As for an explanation, you can use LIKE to perform a match using wildcards, namely _ and %. An underscore matched any character, but just once, a % matches any character any number of times. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.