PDA

View Full Version : having some problems with an if condition + forumula


Spank
08-02-2008, 10:16 PM
I've got a formula to work out a percentage from user fields, which is the postbit_display_start hook the formula looks like this:
$percentage = (intval($post['field7']) / intval($post['field6'])) * 100;
All works well unless any of the values in the fields are 0, the fields need to be set to 0 by default, and staff members will edit these fields.

So what I'm trying to do is add an if conditional to just display 0 if field 6 is 0

Here's what I've got

$percentage = <if condition = "(post['field6']))=0">0 </if> <else />(intval($post['field7']) / intval($post['field6'])) * 100;


Obviously it doesn't work, which is why I'm posting. If anyone can help, that'd be great. I'm so dreadfully new at this I can't work it out =D

MoT3rror
08-02-2008, 10:19 PM
That is template if condition, it doesn't work in php. $percentage = ($post['field6'] ? $post['field7'] / $post['field6']: 0);

Spank
08-02-2008, 10:29 PM
Thanks MoT3rror, but where would I put this? If it's where I want the percentage displayed I wouldn't need the $percentage, would I?

Right now I have the formula a plugin in the hook and then just type $percentage where I want the percentage displayed.

MoT3rror
08-02-2008, 10:36 PM
You would find a hook that is where you need this code and before the template is called. Then you can put $percentage in your template.

Spank
08-02-2008, 10:43 PM
I love you! It works great! Thanks =)