PHP Query Issue

I have the following query that works up to a point and I am a little stuck.
$laser_query = ee()->db->select('t1.entry_id AS id, t1.field_id_1091 AS title, t1.field_id_1141 AS image, t2.url_title AS url_title')
		->from('exp_channel_data t1')
		->where('t1.field_id_3731', $cw)
		->or_where('t1.field_id_3731', $pulsed)
		->or_where('t1.field_id_3731', $pulsednp)
		->or_where('t1.field_id_3731', $quasi)
		->or_where('t1.field_id_3731', $ultrafastfp)
		->or_where('t1.field_id_3731', $ultrafastf)
		->or_where('t1.field_id_3781 <=', $wave_max)
		->join('exp_channel_titles t2', 't2.entry_id = t1.entry_id')
		->get();
		

Open in new window

Line #9: ->or_where('t1.field_id_3781 <=', $wave_max)
I am trying to see if that field contains a number that is equal to or less than $wave_max
The problem is, in the DB table field there are entries like so:
680
 1080
 680,700,800,900,100,000,000,000808
 635
 Magnum 500
 635
 Magnum 500
 680
 Magnum 1000
 680
 Magnum 1500
 665
 Magnum 200
 810
 Magnum 4000
 810
 Magnum 7000
 808
 
The table field is part of a Matrix field in the CMS that stores a bunch of info.  So how can you search a field for values when there are words in there also?
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
You're going to struggle to query your database with such a mix of data. Looks like a pretty poor design for a database.

You may be better off dropping that part of the query, and using php to loop through the results, regexing the numbers out of the string and then seeing whether you want to keep the record or not.

As soon as the normalisation of a database gets messy, your queries start to become unmanageable - I suspect that's the case here.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
The CMS Expression Engine has a plugin that allows you to create Matrix fields.  This is how the Matrix Plugin stores the info in the DB.  I agree that it is not the best way to store Data in the DB but I'm stuck with what I have and need to figure a way.

So if I use RegEx I have changed my query to look like the following but I don't think it is right cause it is not returning anything:
		$laser_query = ee()->db->query(
		SELECT t1.entry_id AS id, t1.field_id_1091 AS title, t1.field_id_1141 AS image, t2.url_title AS url_title
		FROM exp_channel_data t1, exp_channel_titles t2 
		WHERE (t1.field_id_3731 = $cw || t1.field_id_3731 = $pulsed || t1.field_id_3731 = $pulsednp || t1.field_id_3731 = $quasi || t1.field_id_3731 = $ultrafastfp || t1.field_id_3731 = $ultrafastf)
		AND t1.field_id_3781 <= $wave_max REGEXP '/[^0-9]/'
		AND t1.field_id_3781 >= $wave_max REGEXP '/[^0-9]/');

		
		$lb = $laser_query->result_array();
		
		foreach($lb as $row){

Open in new window

rgranlundAuthor Commented:
RegEx was the key that got me in the right direction.  Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.