blackcell Posted August 23, 2009 Share Posted August 23, 2009 I am trying to perform a mysql search based upon the first letter of the users choice. I need to tell mysql to to look only at the first letter of the value in table_field. I have 2 years of experience with mysql but I haven't really cracked into using mysql's advanced usage and want to start. I thought maybe substring(string,len) from mysql's website was what I wanted but either that isn't it or I am not using it right. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/171492-solved-equivalent-to-phps-substrvalue-for-mysql/ Share on other sites More sharing options...
asmith Posted August 23, 2009 Share Posted August 23, 2009 QUERY...WHERE SUBSTRING(FIELD, 1, 1) = 'a' Notice substring is like SUBSTRING(FIELD, 1, 1) (For the first character) while PHP substr is like substr($text, 0, 1) Quote Link to comment https://forums.phpfreaks.com/topic/171492-solved-equivalent-to-phps-substrvalue-for-mysql/#findComment-904348 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 LIKE '%a' (a being a random letter) would probably be faster since it would use indexes. Quote Link to comment https://forums.phpfreaks.com/topic/171492-solved-equivalent-to-phps-substrvalue-for-mysql/#findComment-904350 Share on other sites More sharing options...
blackcell Posted August 23, 2009 Author Share Posted August 23, 2009 Can you explain the like '%a' and use it in an example? I think I know where your going but I am still fuzzy on it. Quote Link to comment https://forums.phpfreaks.com/topic/171492-solved-equivalent-to-phps-substrvalue-for-mysql/#findComment-904360 Share on other sites More sharing options...
asmith Posted August 24, 2009 Share Posted August 24, 2009 AFAIK corbin is offering a 'faster' way. An example of like: SELECT FIELD FROM TABLE WHERE FIELD LIKE 'a%' Gives you all the fields starting with the letter a WHERE FIELD LIKE '%a%' Gives you all the fields that has the letter a in them WHERE FIELD LIKE '%a' Gives you all the fields that ENDS with the letter a Quote Link to comment https://forums.phpfreaks.com/topic/171492-solved-equivalent-to-phps-substrvalue-for-mysql/#findComment-905147 Share on other sites More sharing options...
blackcell Posted September 8, 2009 Author Share Posted September 8, 2009 Awesome, thank you much. Quote Link to comment https://forums.phpfreaks.com/topic/171492-solved-equivalent-to-phps-substrvalue-for-mysql/#findComment-914586 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.