Jump to content
gottberg

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

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites

I believe it is as simple as doing: 

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

 

Share this post


Link to post
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. 😞

Share this post


Link to post
Share on other sites

It's probabably more like:

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

 

Share this post


Link to post
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. 🙂 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...