I have a table where users enters there username in both lower case(eg: arup) and uppercase(eg: Arup) or both (eg: aRuP).
But my problem is now that if I search database to show member username like %Arup, mysql returns empty result if not 开发者_如何学Cfounds exactly.
id | username | name | sex
1 arUp Arup Sarma Male
<?php
$q=strip_tags($_POST['user']); /// eg. Arup
$qry=mysql_fetch_row(mysql_query("SELECT id,name,sex FROM membertable WHERE username='%$q'"));
echo $qry['0']."<br>".$qry['1']."<br>".$qry['2'];
?>
/// Now above sql query will return zero result as there is no username in the form of arUp.
How to make SQL query Case-insensitive ? anyone help please...
I think that this link could help to understand your problem...
Anyway you could solve your problem with this:
SELECT * FROM your_table
WHERE LOWER(username) LIKE '%arup'
You can call UPPER
on both sides of the comparison:
SELECT id,name,sex FROM membertable WHERE UPPER(username) = UPPER('%$q')
The "right way", according to the official manual, is choosing a case-insensitive collation, which might be faster but is also more complicated.
based on this: http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
i'd try this:
where username COLLATE latin1_swedish_ci = '%$q'
精彩评论