CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 ingnore white space while searching numbers

Print topic Send  topic

Author Message
Troyh

Posts: 13
Posted: 12/30/2008, 6:49 PM

hi there

i have a search wich searches for phone numbers ie: home mobile etc.

it works good but for example if i search for ie: 555 55 99 it comes up but if i search 5555599 it dosent, is there a way to search while ingoring white space.

and also

if i search (03) 555 55 99 it donsent come up becauce of the () brackets is there a way around that?

regards
Troy
View profile  Send private message
datadoit
Posted: 12/31/2008, 8:03 AM

Troy, what's your database?
Troyh

Posts: 13
Posted: 12/31/2008, 11:50 AM

im using ccs 3.2, mysql and php

sorry i should have put that in before

regards Troy
View profile  Send private message
datadoit
Posted: 12/31/2008, 1:58 PM

Have a look at MySQL 5+ REGEXP:

http://dev.mysql.com/doc/refman/5.1/en/regexp.html

It may require some tweaking using PHP preg_replace also:

http://www.webmasterworld.com/php/3120488.htm

Basically it sounds like you want to search only for the numbers entered
and ignore all inputs other than numbers, while at the same time
ignoring all non-number characters that are stored in the database.
Perfect for searching through phone number fields, where there may exist
parens, dashes, spaces, etc.

The above links should get you started in that direction. When you
solve it post your solution so I can use it. :)
Oper


Posts: 1195
Posted: 01/02/2009, 6:57 AM

Troy how big is the Database search you have 2 option.

we have done both

1) Always keep a 2nd field just for number

but if not a huge database you could use custom function

100,000 records?
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
Troyh

Posts: 13
Posted: 01/02/2009, 1:55 PM

hi oper

the database will only have a max of 700 records

the search has 4 search text boxes.

1: home phone
2: mobile
3: office
4:surgery

i was hopeing to for example type in : 035556688 and it would bring up (03) 3555 6688 record

and for example type in: 444555777 and it would bring up : PVT 444 555777

i was thinking the main thing i need is for the search to ignore the white space between the numbers.

regarding the () brackets and the PVT text in front of the number i could create a new field for the (03) and PVT information to go in , and the numbers in a seperate field there for it would be the white pace to resove.

View profile  Send private message
Oper


Posts: 1195
Posted: 01/04/2009, 7:38 AM

ok for that small amount of record no issue at all.

as soon i got to the office i will show a simple way to doit without changing the COde
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
Oper


Posts: 1195
Posted: 01/06/2009, 8:55 AM

Troy,

This is the Function.
could be optimized more but for you records under 10,000 not a problem

this is the funcion we use on class for students.


NOTE: This is a Custom MYSQL Function
Just run this script and will create your function then later just use:

stripcharacter(Telephone)={whaever here}

so any number will work (809) 537-2600, LO809537-2600

example"
select * from mydatabase where stripcharacter(Telephone) = '8095372600'
or
select * from mydatabase where stripcharacter(Telephone) like '%5372600%'

to test result you could do this:
select stripcharacter(Telephone) from yourdatabase


  
CREATE DEFINER = 'YOURUSER'@'%' FUNCTION `StripCharacter`(vSTR CHAR(50))  
    RETURNS char(50) CHARSET latin1  
    NOT DETERMINISTIC  
    CONTAINS SQL  
    SQL SECURITY DEFINER  
    COMMENT ''  
BEGIN  
declare X1,X2 INT DEFAULT 0;  
declare vSTRreturn char(50) DEFAULT '';  
  
  
WHILE x1 < LENGTH(vSTR) DO  
   set x1=x1+1;  
   if SUBSTRING(vSTR,X1,1)>= '0' and SUBSTRING(vSTR,X1,1)<= '9' THEN  
      set vSTRReturn = concat(vSTRReturn,SUBSTRING(vSTR,X1,1));  
   End If;  
End WHILE;  
  
  RETURN vSTRReturn;  
END;  

_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
datadoit
Posted: 01/06/2009, 9:22 AM

Oper this is good stuff!

I'm failing syntax at line 8, which is the

declare X1,X2 INT DEFAULT 0;

line. It's acting like it doesn't like any declaration at that point,
which doesn't make sense. It 'looks' okay.

We're on v5.whatever of MySQL. Any clue as to what's missing?
Oper


Posts: 1195
Posted: 01/06/2009, 10:10 AM

odd maybe MYSQL version.

i just copy a paste righ from the forum in case some odd chars trasformation cuase teh forum etc.
but worked ok.
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
Oper


Posts: 1195
Posted: 01/06/2009, 10:14 AM

* Using .67 version of mysql try this one:

  
CREATE DEFINER = 'YOURUSER'@'%' FUNCTION `StripCharacterX`(vSTR CHAR(50))    
    RETURNS char(50) CHARSET latin1    
    NOT DETERMINISTIC    
    CONTAINS SQL    
    SQL SECURITY DEFINER    
    COMMENT ''    
BEGIN    
declare X1 INT;    
declare X2 INT;  
declare vSTRreturn char(50);    
SET X1=0;  
SET X2=0;  
SET vSTRreturn = '';  
    
    
WHILE x1 < LENGTH(vSTR) DO    
   set x1=x1+1;    
   if SUBSTRING(vSTR,X1,1)>= '0' and SUBSTRING(vSTR,X1,1)<= '9' THEN    
      set vSTRReturn = concat(vSTRReturn,SUBSTRING(vSTR,X1,1));    
   End If;    
End WHILE;    
    
  RETURN vSTRReturn;    
END;    

_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
datadoit
Posted: 01/06/2009, 7:08 PM

Turns out to be a Navicat issue.

Working for me now! Ripping through about 50k records for a phone
number returned three records in about 8 seconds or so. Not too bad.

Thanks for sharing!
Oper


Posts: 1195
Posted: 01/10/2009, 6:19 AM

Quote datadoit:
Turns out to be a Navicat issue.

Working for me now! Ripping through about 50k records for a phone
number returned three records in about 8 seconds or so. Not too bad.

Thanks for sharing!

odd should not be that slow on 5k records we did the same for a 100k records and
was like 5-8sec at that time. (maybe server configuration)

we still use this approach on some site, but i preferer alway record a 2nd field at the same time cleared. (Disk space is so cheap at this time, customer prefer speed)


Hope Troy makeit



_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
datadoit
Posted: 01/10/2009, 6:41 AM

Oper wrote:
> odd should not be that slow on 5k records we did the same for a 100k records
> and
> was like 5-8sec at that time. (maybe server configuration)
>

You're right. It is only a few seconds. Forgot I was running through a
remote tunnel before, hence the latency. Do you think with or without
an index on the searched field helps/hinders?
Oper


Posts: 1195
Posted: 01/11/2009, 5:29 AM

Quote datadoit:
Oper wrote:
> odd should not be that slow on 5k records we did the same for a 100k records
> and
> was like 5-8sec at that time. (maybe server configuration)
>

You're right. It is only a few seconds. Forgot I was running through a
remote tunnel before, hence the latency. Do you think with or without
an index on the searched field helps/hinders?

index wont help since the function has to be analized and executed in every record :(
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.