Justtechjobs.com Find a programming school near you






Online Campus Both


php-db | 2001062

Re: [PHP-DB] Modify Query, or sift through results? From: Jason Stechschulte (jpstech <email protected>)
Date: 06/28/01

On Wed, Jun 27, 2001 at 08:54:04AM -0500, Joseph Koenig wrote:
> I've got a script that searches a db every night and sends out e-mail if
> it finds something a person would be interested in, based on criteria
> they gave us. The problem is that I have one field that stores regions
> of the country in a very unpleasant way. It stores them as:
>
> Northeast;West;South
>
> So all of the regions for one record go into one field. The problem is
> that when searching that, if someone has a preference of 'North', I
> dont want to pull records that have 'Northeast', as would happen with
> the above example. Is there a way to modify the MySQL query so as to
> find only 'North', keeping in mind that 'North' may be the 3rd in a list
> of semi-colon separated regions? Or do I need to sift through the
> results in PHP to clean them up? Thanks,

You can certainly have MySQL do the work. I can't modify your query,
because you didn't give it to us, but I can give you an example.

<?php
$sql = select * from your_table where your_column rlike "North(;|$)";
?>

This will do a regular expression match. If either North with a semicolon
directly after it or North and the end of the string is found, the
row will be returned.

-- 
Jason Stechschulte
jpstech <email protected>
--
If you're going to define a shortcut, then make it the base [sic] darn
shortcut you can.
             -- Larry Wall in <199709241628.JAA08908 <email protected>>

-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>