Hi Bob,

How about something like this:

<?php

//somewhere in PHP before the query:
if(($hyphenLoc=stristr($partNum,'-'))===false){
  //no hyphen was entered on the form, so now we add one as optional
  $partNumSql=" '".substr($partNum,0,2)."-? ".substr($partNum,2)."'";
}else{
  //hyphen exists in partnum, so we turn it into an optional hyphen
  $partNumSql=" '".implode('-?',explode('-',$partNum))."'";
}

$qry=<<<EOL
SELECT *
  FROM a_table
 WHERE part_num REGEX $partNumSql
EOL;

?>


--- In [email protected], Bob Sawyer <[EMAIL PROTECTED]> wrote:
> OK, here's a fairly standard, non-Oracle question for you all. A friend
> of mine has asked me to open up his part-search script a little bit by
> making it so that if someone searches for a part number 'cp7940'
> they'll get matching results that include dashes, such as 'cp-7940'.
> 
> I've already altered his script (this is MySQL now, by the way) so that
> it's only searching on the first three characters of whatever someone
> enters. So if they enter 'cp7940' into the search field, they'll get
> anything matching 'cp7%' but that doesn't take the dashes into
> consideration. I don't want to remove all dashes from the database, as
> that will mess up the inventory system. 
> 
> SO - how do I get a search term that does NOT contain dashes to bring
> forth search results that DO contain dashes? The only thing I could
> think of was to do the old 'temporary table' thing again and strip out
> all dashes as each part was written to the temp table. However, he has
> several hundred thousand parts in his database, so I really don't want
> to even think about the server load that would cause.
> 
> Ideas?
> 
> Thanks,
> -bob
> 
> 
>               
> __________________________________ 
> Do you Yahoo!? 
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/





Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to