Jump to content

SOLVED: Find if number is between two numbers in different fields


gottberg
 Share

Recommended Posts

Hi,

The template has 2 fields with numbers, lets call them n1 and n2.

I want to find the page which fits my current number.

For example my number = 10

Pages:

PageID 1: n1 1 - n2 10
PageID 2: n1 11 - n2 20
PageID 3: n1 21 - n2 30

So i want this to return the pageID 1.

With mySQL it would be something like this:

SELECT * FROM numberTable WHERE 1265 BETWEEN `FROM` AND `TO`;

I have tried multiple selectors but can't get it to work.

Any suggestions?

Edited by gottberg
SOLVED
Link to comment
Share on other sites

4 minutes ago, louisstephens said:

I believe it is as simple as doing: 


<?php
    $p = $pages->get('template=your-template, n1|n2=10'); 
    echo $p->id;
?>

 

Thanks for the fast reply!

I still get zero results, so i seems like its not working. 😞

Link to comment
Share on other sites

7 minutes ago, LostKobrakai said:

It's probabably more like:


$pages->get("template=your-template, n1<=$myNumber, n2>=$myNumber")

 

Thanks, this got it working! I tried this earlier but i must have had a spelling error. 🙂 

Link to comment
Share on other sites

On 5/21/2019 at 7:23 PM, LostKobrakai said:

It's probabably more like:


$pages->get("template=your-template, n1<=$myNumber, n2>=$myNumber")

 

Hi,

This works great for numbers above hundred but it does not work when the range is 61-99 for example. 

Do you know what could cause the problem?

 

EDIT: I solved the issue by using findOne(), wierd but now i get the results i wanted.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...