vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How to display the average value of two field in postbit (https://vborg.vbsupport.ru/showthread.php?t=216681)

theduyet 06-21-2009 02:51 AM

How to display the average value of two field in postbit
 
Asume that my user table has two columns .One is votetotal and the other is votenum.I can print the value of them in postbit just using : post[votetotal],and post[votenum].However,i only want to print the average value of them when votenum>0 and 0 when votenum<0.
How can i do that?

Lynne 06-21-2009 03:19 AM

Are you using a plugin to get the votetotal and votenum? If so, just add the php to get the average. If you aren't using a plugin, you may be able to do the math in the template just take a look at this article - Perform simple calculations inside templates!. If you can't do it in the template, then you'll have to add a plugin.

theduyet 06-21-2009 04:20 AM

I tried to do it in the templates.
Quote:

<if condition="$post[votenum]!=0">
<if condition="$rateave = $post[votetotal]/$post[votenum]"></if>
$rateave
</if>
It's okey.However the result is not good looking.
Example if the votetotal is 11,the votenum is 3.It will print 3.6666666666667 .
I just want to get the value 3.67 or 4.

--------------- Added [DATE]1245564040[/DATE] at [TIME]1245564040[/TIME] ---------------
Quote:

<if condition="$post[votenum]!=0">
<if condition="$rateave = $post[votetotal]/$post[votenum]"></if>
<if condition="$rateave >0 && $rateave < 1.5"><if condition="$rateave1=1"></if></if>
<if condition="$rateave >=1.5 && rateave< 2.5"><if condition="$rateave1=2"></if></if>
<if condition="$rateave >=2.5 && rateave<3.5 "><if condition="$rateave1=3"></if></if>
<if condition="$rateave >=3.5 &&rateave<4.5"><if condition="$rateave1=4"></if></if>
<if condition="$rateave >=4.5 "><if condition="$rateave1=5"></if></if>
$rateave1
</if>
Because the maximum rated score is 5 (5 star)I tried to use this and it works.
However,if i want to use the plugin,how can i do that?
Thanks.

Lynne 06-21-2009 03:06 PM

You would write the php to do this and probably use a hook location like postbit_display_complete. Plugin System


All times are GMT. The time now is 05:29 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01153 seconds
  • Memory Usage 1,718KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete