Hi Bob,

I had a feeling I could write your query in one SELECT statement, so I
tried and succeeded.  Here is what I came up with:

-- 
-- Table structure for table `ky_test`
-- 

CREATE TABLE `ky_test` (
  `id` int(11) NOT NULL auto_increment,
  `part` varchar(15) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=7 ;

-- 
-- Dumping data for table `ky_test`
-- 

INSERT INTO `ky_test` VALUES (1, 'ps1234');
INSERT INTO `ky_test` VALUES (2, 'ps-3345');
INSERT INTO `ky_test` VALUES (3, 'ps-1234');
INSERT INTO `ky_test` VALUES (4, 'fd45456');
INSERT INTO `ky_test` VALUES (5, 'ps-9999');
INSERT INTO `ky_test` VALUES (6, 'ps1112');


SELECT *
  FROM ky_test
WHERE part REGEXP IF(INSTR('ps1234','-'),
                    
CONCAT(SUBSTRING('ps-1234',1,2),'-?',SUBSTRING('ps-1234',4)),
                    
CONCAT(SUBSTRING('ps1234',1,2),'-?',SUBSTRING('ps1234',3)))


You just need to replace all the string quoted parts in the query with
the PHP variable and it should pull all the part numbers that both do
and do not have hyphens.

Cheers,
Keith.






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