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. Link to comment https://forums.phpfreaks.com/topic/127747-filtering-results-by-first-letter-using-an-url-variable/ 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()); Link to comment https://forums.phpfreaks.com/topic/127747-filtering-results-by-first-letter-using-an-url-variable/#findComment-661293 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. Link to comment https://forums.phpfreaks.com/topic/127747-filtering-results-by-first-letter-using-an-url-variable/#findComment-661328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.