case sensitive query?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
noclist
Forum Newbie
Posts: 7
Joined: Mon Jun 29, 2009 11:12 am

case sensitive query?

Post by noclist »

I'm pulling records from a database with these 2 queries:

Code: Select all

$stud=$_POST['stud'];
$stud=mysql_real_escape_string($stud);
 
if ($_POST['stud']!="")
{
 
$sql="SELECT * FROM movies WHERE studio like  '%" . $stud . "%'";
and

Code: Select all

$dir=$_POST['dir'];
$dir=mysql_real_escape_string($dir);
 
if ($_POST['dir']!="")
{
 
$sql="SELECT * FROM movies WHERE director like  '%" . $dir . "%'";
However, the search variable I am using in the first query($stud) seems to be case sensitive while $dir is not.
For example, if I want to find all movies by the studio Warner Brothers, searching for 'warner' returns no results. But at the same time searching for 'scorsese' in my director search will return results of Martin Scorsese.

Is there anyway to explain this? The code of both are identical minus the variable name. Thanks in advance if you have any advice.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: case sensitive query?

Post by Skara »

http://dev.mysql.com/doc/refman/5.0/en/ ... ivity.html
Does all of that answer your question?
noclist
Forum Newbie
Posts: 7
Joined: Mon Jun 29, 2009 11:12 am

Re: case sensitive query?

Post by noclist »

No, could you sum it up in laymens terms for me?

Does it explain how one of my variables is treated as case sensitive and the other not? They're both just text characters and treated identically in my database and code.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: case sensitive query?

Post by jackpf »

Unless they're different data types then I doubt that's the case.

However, if you want it to be case sensitive then you can put BINARY before the column names, if not, run LOWER() on them both.
noclist
Forum Newbie
Posts: 7
Joined: Mon Jun 29, 2009 11:12 am

Re: case sensitive query?

Post by noclist »

Thanks, how would i go about running lower? I would like both searches to be case insensitive. A google search for the lower() function didn't return anything useful for me.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: case sensitive query?

Post by jackpf »

Post Reply