PDA

View Full Version : How to display the average value of two field in postbit


theduyet
06-21-2009, 02:51 AM
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! (https://vborg.vbsupport.ru/showthread.php?t=188930). 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.
<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 1245564040 at 1245564040 ---------------

<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 (http://www.vbulletin.com/docs/html/plugin_system)