Advanced MySQL Query & Tab-Delimited Value

6 posts by 3 authors in: Forums > CMS Builder
Last Post: August 24, 2012   (RSS)


Here's a brain teaser...

I'm trying to construct an advanced MySQL query for a list in the editor.

I need to test whether any of the numbers in a tab-delimited string match a selected number.

I've tried all the usual methods...

SELECT * FROM `<?php echo $TABLE_PREFIX ?>table` WHERE 'string' LIKE '%number%'

SELECT * FROM `<?php echo $TABLE_PREFIX ?>table` WHERE 'string' LIKE '%\tnumber\t%'

...but nothing seems to work.

Have I got it the wrong way around?

:0/

Perchpole

Re: [Perchpole] Advanced MySQL Query & Tab-Delimited Value

By Jason - August 24, 2012

Hi,

Is "string" a multi value field in the database, or a string that was already taken from the database?
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Advanced MySQL Query & Tab-Delimited Value

Hi, Jason -

The "string" was formed as a result of a multi-select list - created in another table/editor.

As I understand it, this would create a tab-delimited string of values.

Perch

Re: [Dave] Advanced MySQL Query & Tab-Delimited Value

HI, Dave -

Still no joy. What I failed to mention is that the number in this instance is chosen via the preceding list option in the editor.

This then triggers the following list to refresh - changing the values in the list. The full code should be:

SELECT * FROM `<?php echo $TABLE_PREFIX ?>table` WHERE 'string' LIKE '%\t<?php echo $ESCAPED_FILTER_VALUE ?>\t%'

When I change the value in the firt menu, the second menu shows the "Loading..." message - but is always empty.

:0/

Perch

Re: [Perchpole] Advanced MySQL Query & Tab-Delimited Value

By Dave - August 24, 2012

What is the actual query, eg: what do you have in place of 'string'? Can you copy and paste the exact query you are using?

Does it work if you hard code a number you know exists in the database and then change the preceding list? For example:
SELECT * FROM `<?php echo $TABLE_PREFIX ?>table` WHERE 'string' LIKE '%\t123\t%'

And what do you see when you change the query to this:
SELECT '%\tnumber\t%', 'string' FROM `<?php echo $TABLE_PREFIX ?>table`

Also, If 'string' is a fieldname make sure you don't have quotes around it.

Let me know, thanks.
Dave Edis - Senior Developer
interactivetools.com