Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Rounding a template var.
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #14
RE: Rounding a template var.
I put the below code in my template:

Code:
1
2
3
4
5
6
<setvar test>intval($GLOBALS['threadfields']['pfrating12']['value'])</setvar>
<setvar test1>intval($GLOBALS['threadfields']['pfrating1']['value'])</setvar>
<setvar myratings>array_filter(array(intval($GLOBALS['threadfields']['pfrating1']['value']), intval($GLOBALS['threadfields']['pfrating2']['value']), intval($GLOBALS['threadfields']['pfrating12']['value'])))</setvar>
Average: <?=count($GLOBALS['tplvars']['myratings']) ? array_sum($GLOBALS['tplvars']['myratings']) / count($GLOBALS['tplvars']['myratings']) : 0 ?>
Test: {$tplvars['test']}
Test1: {$tplvars['test1']}


The output for test (a "not-set") was 0.
The output for test1 (a value of 4) was 4.

The output for Average was 0.

I think - though I was unable to test it as I could not figure out how to write it - that the count is always returning zero, whether the values are filled in or not, and this is returning a value of zero for the average.



[Image: leelink.gif]
MYBB1.6 & XThreads
(This post was last modified: 05-13-2013 12:03 AM by leefish.)
05-12-2013 11:48 PM
Visit this user's website Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Rounding a template var. - leefish - 04-21-2013, 04:42 AM
RE: Rounding a template var. - ZiNgA BuRgA - 04-21-2013, 04:58 PM
RE: Rounding a template var. - leefish - 04-21-2013, 06:17 PM
RE: Rounding a template var. - ZiNgA BuRgA - 04-21-2013, 07:30 PM
RE: Rounding a template var. - leefish - 04-21-2013, 08:19 PM
RE: Rounding a template var. - ZiNgA BuRgA - 04-21-2013, 09:39 PM
RE: Rounding a template var. - leefish - 04-21-2013, 09:47 PM
RE: Rounding a template var. - leefish - 05-05-2013, 02:20 AM
RE: Rounding a template var. - ZiNgA BuRgA - 05-05-2013, 10:09 PM
RE: Rounding a template var. - leefish - 05-10-2013, 02:36 AM
RE: Rounding a template var. - ZiNgA BuRgA - 05-10-2013, 09:37 AM
RE: Rounding a template var. - leefish - 05-10-2013, 06:04 PM
RE: Rounding a template var. - ZiNgA BuRgA - 05-12-2013, 11:04 AM
RE: Rounding a template var. - leefish - 05-12-2013 11:48 PM
RE: Rounding a template var. - ZiNgA BuRgA - 05-13-2013, 02:11 PM
RE: Rounding a template var. - leefish - 05-13-2013, 09:25 PM
RE: Rounding a template var. - ZiNgA BuRgA - 05-14-2013, 09:34 AM
RE: Rounding a template var. - leefish - 05-14-2013, 06:48 PM

 Standard Tools
Forum Jump: