Current location: Hot Scripts Forums » Other Discussions » Database » Database select querry


Database select querry

Reply
  #21 (permalink)  
Old 12-01-09, 06:24 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by carters-site View Post
My major was in Computer Science
Lol, that explains it. (Just kidding!)

Seriously though, as programmers, we think differently and we're often very literal. My friends will ask me if I know what time it is, and I'll say, "Yes."

They'll roll their eyes and ask me, okay, would I tell them what time it is, and I'll think for a moment, and I'll say, "Yes". They'll roll their eyes again, and yell, "Well, what &#$%! time is it??" And I'll say, "It's 2:30. Why didn't you ask?"

It's not my problem if they don't ask the right question, is it?

When my wife asks me if I want burgers or chicken for dinner, I say, "Yes!". Then she mutters a whole lot of words in Khmer that I don't recognize, but I'm pretty sure it's something about how much she loves me like crazy, or words to that effect.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #22 (permalink)  
Old 12-01-09, 09:47 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I hope this helps.

This is an expanded version of the earlier code. It has two regular expressions. The first surrounds any digit strings with spaces and punctuation, the second removes any extra spaces from the entered string.

The $aStrings array simulates search entries from users, 'Potterton Puma 80e' is the the 'target'.

PHP Code:

<?php

$link 
mysql_connect('localhost''user''password');
if (!
$link)
    die(
'Could not connect: ' mysql_error());

$aStrings=array('potterton','potterton     puma','80e','puma80e','pott puma','potterton 80e','potterton puma','puma 80 e','potterton
 80 e'
);
foreach (
$aStrings as $k => $v)
{
        
$sQuery='SELECT "Potterton Puma 80e" REGEXP \''.make_regexp($v).'\' AS \'found\'';
        
$rResult=mysql_fetch_assoc(mysql_query($sQuery));
        echo ((
$rResult['found']==1)?'Match':'No match').' on '.$v.' [ '.$sQuery.' ]'."\n";
}
mysql_close($link);

function 
make_regexp($sString)
{
        return 
preg_replace(array('/(\d+)/','/[\s]+/'),array('[[:print:][:punct:]]*${1}[[:print:][:punct:]]*','[[:space:]]*'),$sStri
ng
);
}
?>
Output (matches code above)

Code:
Match on potterton [ SELECT "Potterton Puma 80e" REGEXP 'potterton' AS 'found' ]
Match on potterton     puma [ SELECT "Potterton Puma 80e" REGEXP 'potterton[[:space:]]*puma' AS 'found' ]
Match on 80e [ SELECT "Potterton Puma 80e" REGEXP '[[:print:][:punct:]]*80[[:print:][:punct:]]*e' AS 'found' ]
Match on puma80e [ SELECT "Potterton Puma 80e" REGEXP 'puma[[:print:][:punct:]]*80[[:print:][:punct:]]*e' AS 'found' ]
No match on pott puma [ SELECT "Potterton Puma 80e" REGEXP 'pott[[:space:]]*puma' AS 'found' ]
Match on potterton 80e [ SELECT "Potterton Puma 80e" REGEXP 'potterton[[:space:]]*[[:print:][:punct:]]*80[[:print:][:punct:]]*e' AS 'found' ]
Match on potterton puma [ SELECT "Potterton Puma 80e" REGEXP 'potterton[[:space:]]*puma' AS 'found' ]
Match on puma 80 e [ SELECT "Potterton Puma 80e" REGEXP 'puma[[:space:]]*[[:print:][:punct:]]*80[[:print:][:punct:]]*[[:space:]]*e' AS 'found' ]
Match on potterton 80 e [ SELECT "Potterton Puma 80e" REGEXP 'potterton[[:space:]]*[[:print:][:punct:]]*80[[:print:][:punct:]]*[[:space:]]*e' AS 'found' ]
The REPLACE approach works, but there may be a performance hit, and, if any new characters are introduced, it would have to be updated.

Last edited by wirehopper; 12-01-09 at 09:56 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me on How to Select Records from the database airprince Visual Basic 2 08-16-06 02:06 AM
select variable from one database to use in another?!?? Deansatch PHP 1 07-07-06 02:24 PM
Dynamic select box from database values PrashantJsp JavaScript 2 05-04-05 12:29 AM
PHP Can't select database EST PHP 4 08-19-03 10:14 AM


All times are GMT -5. The time now is 05:09 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.