Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/203684-up-and-low-case-problem/
Share on other sites

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'] . '%"';

}

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.