PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 7th, 2002, 07:46 PM
Failte_PHP Failte_PHP is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Failte_PHP User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wildcard Searches on numeric column??

The situation is that I have a legacy DB that zero fills all of the numeric fields (it allows for 8 characters in the numeric field in questions so number 33 looks like 00000033). When we created the table we carried over the above format yet converted the data to numeric and zero filled. Thus it looks like the data from the legacy DB and we will be able to pass integrity audits. Anyway now I need to be about to search from a web page (enter wonderful PHP) on this column, but my users may not enter 00000033, they might just enter 33. The treatment of % in my SQL statement seems to make things fall apart as it is meant for strings not numbers. How might I handle a user input of 33 to find what is in the table as 00000033 ? Perhaps some cool built in that will auto zero fill this number? Right now I think I might just write a function to manipulate the user input (easy enough) but I am new to PHP and no need to reinvent the wheel if something already exists.

All thoughts and comments welcome!
Thanks

Reply With Quote
  #2  
Old August 7th, 2002, 07:56 PM
sager sager is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 45 sager User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Wildcard Searches on numeric column??

Why don't you pad the number with 0's before you do your selection. If it's a fixed length field, then that shouldn't be too hard.

Reply With Quote
  #3  
Old August 7th, 2002, 09:39 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Wildcard Searches on numeric column??

Try this:

$zeropadded = sprintf("%08d", $input);


Reply With Quote
  #4  
Old August 8th, 2002, 06:21 PM
Failte_PHP Failte_PHP is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Failte_PHP User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Wildcard Searches on numeric column??

Thanks Matt that works wonderfully, however I might need to have my head checked. It appeared that this was not an issue. One of the beta testers cruised right through with no trouble looking up ID 00000033 as ID 33.
Howeber in the future for other items I know we are going to need something like this.

Again Kudos Matt

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Wildcard Searches on numeric column??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway