Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Calculating variable fields

Quote Reply
Calculating variable fields
Hi,

I'm trying to figure out how I can do simple addition and subtraction calculations using field information entered in a link rather than using javascript. All I'm trying to do is have a person enter a couple numbers, <%int1%> <%int2%> <%int3%> and then manipulate the data when needed such as:

<%int3 + int 2 - int1%>

I've been able to add a predetermined number to a field without any problems, its only when I'm trying to get to variables to work together. I thought it might work differently if I defined the field as an INT, but it doesn't do anything different. Is this possible using links or do I need to come up with something in javascript?

Thanks to anyone who can point me in the right direction...
Perl Hopefull
Quote Reply
Re: [stilton] Calculating variable fields In reply to
Should work with;

Code:
<%set added = $int1 + $int2 + $int3%>
Total together: <%added%>

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Calculating variable fields In reply to
Thanks Andy...somehow I knew you would be the first to reply!

I tried using the set command before, but wasn't able to make it work for some reason as well. If I write <%set added = $int1 + 50%> and then call it up as <%added%>, it works great, but if I use another variable like <%set added = $int1 + $int2%> I don't get anything returned.

I don't know if this might be a factor, but I'm trying to setup a spreadsheet in category view with each link much like an excel spreadsheet, so I'm calling it up on link.html for each link, but as far as I can see, it shouldn't make a difference.

Thanks again for any suggestions,
Perl Hopefull
Quote Reply
Re: [stilton] Calculating variable fields In reply to
heheh.. no problem =)

Have you tried;

<%set added = ($int1 + $int2 + $int3)%>

Another way to see what is happening, is to look in the /admin/templates/default/compiled/link.html.compiled file, and see what is actually going on.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Calculating variable fields In reply to
I used that and did get a new answer...it looks like ($int1 + $int2) ! It's not actually doing the math, but rather printing it out as a string. I never looked at the compiled file before...I'll have to go see what kind of interesting things are in there ;-)

If I haven't exausted your skills yet, any other suggestions would be great!

Thanks Andy,
Perl Hopefull
Quote Reply
Re: [stilton] Calculating variable fields In reply to
Afraid I'm not sure what else to suggest. I'm almost 100% sure that <%set val = $val1 + $val2 ..etc %> has worked for me before :/

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Calculating variable fields In reply to
You have to build these calculations up. Something like this should work:

<%set added = $int1%>
<%set added += $int2%>
<%set added += $int3%>
Quote Reply
Re: [afinlr] Calculating variable fields In reply to
That one worked perfectly! Thanks to both of you guys for your help...I was just realizing how poorly my javascript has gotten!
Perl Hopefull