Jump to content

Recommended Posts

Posted

Hi,

I'm trying to get partial match for fields of type integer, much like how %= and *= selectors works for string. Unfortunately these selectors are not working with numeric fields. Is it possible to do this?

For example, if I have pages with control numbers 14975, 91432, 33333, 32414, 13256

I'm looking for something like:

$pages->find("controlnumber%=14");

that would match 14975, 91432, and 32414, that would work for numeric fields.

Thanks. :)

Posted

Hi Alxndre',
 

I suspect this will require a core change to support. The %= selector maps through to a MySQL LIKE statement - which is a string comparison operator.

Edit: Perhaps you could store a text field (let's say: controlnumber_string) which stores the string version of the value of the controlnumber field. You could make it hidden and have a hook populate it whenever controlnumber was changed. You could then use controlnumber_string in your selector.

  • Like 2
Posted

Or perhaps another approach would be to use a standard SQL query to get an array of page IDs that match the desired controlnumber and then get the pages like this:

$pageIDs = array of pages_id results from SQL query of the field_controlnumber table

$matchingPages = $pages->getById($pageIDs);
Posted

Hi, thanks for your replies.

In SQL, I usually cast the integers to string first so it can be used against LIKE. But I can't find enough examples using $db->query to do it. I'd keep searching for now. Thanks again. :)

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...