web_master Posted June 2, 2010 Share Posted June 2, 2010 Hi, is this possible somehow: if string begin with uppercase use query: ucase(`data`) LIKE "' . $_POST['data'] . '%" if string begin with lowecase use query: lcase(`data`) LIKE "' . $_POST['data'] . '%" so I want to solve problem of ucase and lcase with php... Thnsx in advanced T Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/ Share on other sites More sharing options...
web_master Posted June 2, 2010 Author Share Posted June 2, 2010 Hi, is this possible somehow: if string begin with uppercase use query: ucase(`data`) LIKE "' . $_POST['data'] . '%" if string begin with lowecase use query: lcase(`data`) LIKE "' . $_POST['data'] . '%" so I want to solve problem of ucase and lcase with php... Thnsx in advanced T Maybe ist more clearly if($_POST['data']) { // begin with ucase $Qery = 'ucase(`data`) LIKE "' . $_POST['data'] . '%"'; } if($_POST['data']) { // begin with lcase $Qery = 'lcase(`data`) LIKE "' . $_POST['data'] . '%"'; } Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/#findComment-1066868 Share on other sites More sharing options...
rwwd Posted June 2, 2010 Share Posted June 2, 2010 Hi there webmaster, Are the queries meant to be case sensitive? I just wonder about using strtolower on $_POST data so that if the info in the DB is already lowercase, the search will have a better chance of matching, or have I not understood you correctly. But as you have it there, the 'lcase(`data`) would not work because this is a reference to the table column, and therefore not editable. From the example given, I think as it would be easier to convert all $_POST data to lowercase, this would then get rid of any ambiguity from the search - also as you are using $_POST data in a query, use mysql_real_escape_string() around the $_POST so that you can prevent malicious code injection to your Db. Code with strtolower & mysql_real_escape_string():- `data` LIKE "' .strtolower(mysql_real_escape_string( $_POST['data'])) . '%" Hope this helps, Rw Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/#findComment-1066887 Share on other sites More sharing options...
Psycho Posted June 2, 2010 Share Posted June 2, 2010 You would only need to do such a thing if you are using a collation for your database field which is case sensitive. Since you are trying to write code to work around the case of the input I'm guessing you are using the wrong collation type and should be using a case insensitive collation. Try changin the collation type pf that field to something like "latin1_general_ci". I'm pretty sure the "i" on the end indicates an insensitive collation. http://dev.mysql.com/doc/refman/5.0/en/charset-collation-implementations.html Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/#findComment-1066889 Share on other sites More sharing options...
web_master Posted June 3, 2010 Author Share Posted June 3, 2010 Hi, Ill try a both way that You say, but its dont work. In database I usual use the utf8 bin collation and even in connection I have a mysql_query( 'SET NAMES "utf8"' ); mysql_query( 'SET CHARACTER SET utf8' ); So, for a search in database I want to use the LIKE "' . $_POST['data'] . '%"', but in database store the strings with ucase and lcase too, and I dont know on wich way will user search the text. If put some text in search box with lcase but in database is text stored with ucase he wont find anything... T Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/#findComment-1067083 Share on other sites More sharing options...
phpchamps Posted June 3, 2010 Share Posted June 3, 2010 why dont you convert case to lower on both side while firing query.. like:- lower(`data`) LIKE "' .strtolower(mysql_real_escape_string( $_POST['data'])) . '%" try it... Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/#findComment-1067086 Share on other sites More sharing options...
web_master Posted June 3, 2010 Author Share Posted June 3, 2010 why dont you convert case to lower on both side while firing query.. like:- lower(`data`) LIKE "' .strtolower(mysql_real_escape_string( $_POST['data'])) . '%" try it... phpchamps, You are great - Im a beginner and dont know so much about php programming... and also about mysql, and dont know what and where can I use. Thanks again! Best regards, Tivadar Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/#findComment-1067095 Share on other sites More sharing options...
phpchamps Posted June 3, 2010 Share Posted June 3, 2010 ur wlcme buddy Quote Link to comment https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/#findComment-1067099 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.