solved Can I not use arithmetic in search?

iamtimbo
@iamtimbo
10 years ago
301 posts
However I seem to format my searches, either with or without brackets, the arithmetic seems to be ignored, eg:

{jrCore_list module="jrProfile" search1 = "profile_longitude < ($profile_longitude + 0.02)" limit="100" order_by = "_created desc"}

only returns values 'less than $profile_longitude', but not 'less than $profile_longitude + 0.02'.
updated by @iamtimbo: 03/23/15 12:52:03AM
brian
@brian
10 years ago
10,148 posts
iamtimbo:
However I seem to format my searches, either with or without brackets, the arithmetic seems to be ignored, eg:

{jrCore_list module="jrProfile" search1 = "profile_longitude < ($profile_longitude + 0.02)" limit="100" order_by = "_created desc"}

only returns values 'less than $profile_longitude', but not 'less than $profile_longitude + 0.02'.

No you can't - at least not like that. Jamroom templates are Smarty templates:

http://www.smarty.net/docs/en/

so you need to use the {math} function and assign the output to a variable, then use THAT in your jrCore_list call parameter - i.e.

{math equation="x + y" x=$profile_longitude y=0.02 assign="val"}
{jrCore_list module="jrProfile" search1="profile_longitude < `$val`" limit=100 order_by="_created desc"}

Make sure there are NO spaces around your equal signs as well.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 02/17/15 10:25:50AM
iamtimbo
@iamtimbo
10 years ago
301 posts
Thanks Brian - again!

Every day is a lesson, and I've learned more in the last three weeks than in the last three years! It was never my intention to get into this whole development lark, but I'm getting hooked, and now have a bursting notebook. Sorting my SQL from my Smarty from my PHP is often the issue, but I'm getting there slowly.....

I think I need to create me a JamRoom one of these Smarty cheatsheet posters! http://www.cheat-sheets.org/saved-copy/SmartyCheatSheet.pdf

EDIT: Forgot to add link.....
updated by @iamtimbo: 02/17/15 11:06:03AM
michael
@michael
10 years ago
7,773 posts
From smarty3 this works too:
{$value = 10 + 15}
THE VALUE IS: {$value}

Jamroom 5 runs smarty3
brian
@brian
10 years ago
10,148 posts
Nice Michael - I sometimes forget about the Smarty 3 "shorthand" :)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
SteveX
SteveX
@ultrajam
10 years ago
2,584 posts
Are you trying to find nearby profiles? If so, try something like this:

{$max_lng = $profile_longitude + 0.02}
{$min_lng = $profile_longitude - 0.02}
{$max_lat = $profile_latitude + 0.02}
{$min_lat = $profile_latitude - 0.02}

{jrCore_list module="jrProfile" search1="profile_longitude < `$max_lng`" search2="profile_longitude > `$min_lng`" search3="profile_latitude < `$max_lat`" search4="profile_latitude > `$min_lat`" limit=100 order_by="_created desc"}

If you are then mapping those points, you might want to use a square map as all of those points will be within a square.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 02/17/15 11:27:22AM
brian
@brian
10 years ago
10,148 posts

This is cool - I'd not seen this before. Thanks for sharing it!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net