wright67uk Posted February 6, 2011 Share Posted February 6, 2011 Im a newbie trying to get my head around php and sql, please can anyone help me with a statement, or point me to a place where I can find out? - have tried w3schools. How can I get my like statement to only compare the first two charracters of a value? Let's say $code = EN7 6PX (user has typed this into a html form) for eg . SELECT email FROM treesurgeons WHERE postcode LIKE '%$code%' How can I tell my like statement to only take notice of the first two charracters of the post code (in this case 'EN')? So that I get returned EN4 1PP, EN5 6RT, EN7 3OL etc. Quote Link to comment https://forums.phpfreaks.com/topic/226860-like-statement-for-postcodes/ Share on other sites More sharing options...
requinix Posted February 6, 2011 Share Posted February 6, 2011 1. Throw away everything but the first two characters of the input. 2. Make sure they're letters. 3. Put them in your query as LIKE "EN%" Note that there's only one %. Quote Link to comment https://forums.phpfreaks.com/topic/226860-like-statement-for-postcodes/#findComment-1170595 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.