Gossamer Forum
Home : Products : Gossamer Links : PHP Front End :

Calculations ?!?

Quote Reply
Calculations ?!?
Hi,

I have a field called RATES and I would like to be able to divide 1000 by this number in my PHP templates (i.e. 1000 / RATES = x) and see the results. For example if the RATES number is 5 I would have to see 200 in my php templates. What would be the PHP code that I have to enter in my templates for something like that?

Thanks in advance,
PCMANIAK
Quote Reply
Re: [pcmania] Calculations ?!? In reply to
Mmm...in your templates, does this not work;

<? echo 1000 / $FieldName ?>

That should work. If not, you may need something like this;

<? $calc_number = 1000 / $FieldName; echo $calc_number; ?>

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] Calculations ?!? In reply to
Thanks a lot Andy,

That solved a part of my problem, I used the first code that you entered there but when it gives me the answer it looks like this:
289.85507246377

I just need 289 and not the rest of it! What should I do?

Thanks again,
PCMANIAK
Quote Reply
Re: [pcmania] Calculations ?!? In reply to
How about;

<? $val = 1000 / $FieldName; $var2 = sprintf("%2f", $var); echo $var2; ?>

You may be able to cut this down to;

<? printf("%2f", 1000 / $FieldName); ?>

But I'm not sure how PHP will handle it...

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!

Last edited by:

Andy: Nov 1, 2002, 8:03 AM
Quote Reply
Re: [Andy] Calculations ?!? In reply to
Hi Andy and thanks again for all your help,

it didn't work! it is giving me a bunch of zeros like this: 0.000000

Regards,
PCMANIAK
Quote Reply
Re: [pcmania] Calculations ?!? In reply to
Just tried this locally, and it seems to work now;

<? $var = (1000 / $FieldName); $var2 = sprintf("%2d", $var); echo $var2; ?>

The main problem was I use %2f, and not %2d, and also that the sub to create $var needed to be in brackets for it to be stored in the variable correctly Tongue

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] Calculations ?!? In reply to
Thank you very much Andy Smile It works great now!

Thanks again,
PCMANIAK
Quote Reply
Re: [pcmania] Calculations ?!? In reply to
I would simplify it a bit:

<?php echo floor(1000 / $FieldName); ?>

Dan
Quote Reply
Re: [Dan Kaplan] Calculations ?!? In reply to
I knew you would try to better me...LOL Wink

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] Calculations ?!? In reply to
Quote:
I knew you would try to better me...
Better? Nah. :) Undercut, maybe, as in less is more...

Dan
Quote Reply
Re: [Dan Kaplan] Calculations ?!? In reply to
LOL...at least I know that function exists now...I didn't even realise it was a real function until this thread Crazy

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] Calculations ?!? In reply to
Something cool I learned recently is the shortcut URLs to the PHP manual, allowing you to easily try out something you're not sure if it is an actual function. For example:

http://php.net/floor

Much easier than typing out the /manual/en/floor.php or whatever for the final destination. If it takes you to a non-error page, you know you found the right thing. :)

Dan
Quote Reply
Re: [Dan Kaplan] Calculations ?!? In reply to
Yeah, I knew about that....got shown it by my mate at work Smile Pretty nice....shame Perldoc.com/perl.com doesn't have a similar feature Wink

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!