Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > DB search and case sensitive comparison
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 20th November 08:25
angelo
External User
 
Posts: 1
Default DB search and case sensitive comparison



Hi all,

I have a question and I can't seem to get around the problem or finding a
total solution.

I have a DB with a list of entries, one of the tables has fields and one of
the fields is called the lookup_string field.

This field is used to checkup values when users enter the site (explained
below).


So basically what happens is that the user will enter the site and I will
get their user agent from the $_SERVER variable.

What I want to do is to find out which entries in the DB are present in the
useragent string.

Eg:

lookup_string (in db): "Mozilla"

useragent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15)
Gecko/20080623 Firefox/2.0.0.15'

So what I did was I used the locate function in my mysql query which gives
me the correct result set.

Now what I need to do is to ensure that the lookup_string is in the
useragent string and the CASE is the same: IE: Mozilla and not MOZILLA or
mozilla etc...

I am using the following If (however it fails because its part of the
useragent string and not the whole complete string therefore providing a
mismatch).

if(strcmp($userAgent, $lookup_string)==0){

//matches
}
Else
{

//doesn't match
}

Which way could I accomplish searching for the lookup_string in the
useragent and that it's the correct case?

Thanks in advance.

Angelo
  Reply With Quote


 


2 20th November 08:25
nospam
External User
 
Posts: 1
Default DB search and case sensitive comparison



strpos(), ereg() or preg_match() should work, take your pick. strpos()
most likely faster for this simple match.

if (strpos($userAgent, $lookup_string) !== false) {
//matches
} else {
//no matchy matchy
}

-Shawn
  Reply With Quote
3 20th November 08:26
angelo
External User
 
Posts: 1
Default DB search and case sensitive comparison


Hi all,

I have a question and I can't seem to get around the problem or finding a
total solution.

I have a DB with a list of entries, one of the tables has fields and one of
the fields is called the lookup_string field.

This field is used to checkup values when users enter the site (explained
below).


So basically what happens is that the user will enter the site and I will
get their user agent from the $_SERVER variable.

What I want to do is to find out which entries in the DB are present in the
useragent string.

Eg:

lookup_string (in db): "Mozilla"

useragent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15)
Gecko/20080623 Firefox/2.0.0.15'

So what I did was I used the locate function in my mysql query which gives
me the correct result set.

Now what I need to do is to ensure that the lookup_string is in the
useragent string and the CASE is the same: IE: Mozilla and not MOZILLA or
mozilla etc...

I am using the following If (however it fails because its part of the
useragent string and not the whole complete string therefore providing a
mismatch).

if(strcmp($userAgent, $lookup_string)==0){

//matches
}
Else
{

//doesn't match
}

Which way could I accomplish searching for the lookup_string in the
useragent and that it's the correct case?

Thanks in advance.

Angelo
  Reply With Quote
4 20th November 08:27
nospam
External User
 
Posts: 1
Default DB search and case sensitive comparison


strpos(), ereg() or preg_match() should work, take your pick. strpos()
most likely faster for this simple match.

if (strpos($userAgent, $lookup_string) !== false) {
//matches
} else {
//no matchy matchy
}

-Shawn
  Reply With Quote
5 20th November 08:27
dmagick
External User
 
Posts: 1
Default DB search and case sensitive comparison


Make the database do the work if possible.

mysql> select * from a where a like '%MOZILLA%';
+---------+
| a |
+---------+
| Mozilla |
| MOZILLA |
+---------+
2 rows in set (0.00 sec)

mysql> select * from a where a like BINARY '%MOZILLA%';
+---------+
| a |
+---------+
| MOZILLA |
+---------+
1 row in set (0.00 sec)


--
Postgresql & php tutorials
http://www.designmagick.com/
  Reply With Quote
6 20th November 08:28
dmagick
External User
 
Posts: 1
Default DB search and case sensitive comparison


Make the database do the work if possible.

mysql> select * from a where a like '%MOZILLA%';
+---------+
| a |
+---------+
| Mozilla |
| MOZILLA |
+---------+
2 rows in set (0.00 sec)

mysql> select * from a where a like BINARY '%MOZILLA%';
+---------+
| a |
+---------+
| MOZILLA |
+---------+
1 row in set (0.00 sec)


--
Postgresql & php tutorials
http://www.designmagick.com/
  Reply With Quote


 


Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Php 5 forum, Apache forum, Iis forum, Functions forum, Classes forum, Librarys forum, Bugs forum, Postgres forum, Mysql forum, Paradox forum, Ms sql forum, Configurations forum, Php.ini forum, Problems forum, Scripting forum, Css forum, General forums, Off-topic talk, Links, Extra forums, Php


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666