Calcul note moyenne Php sur page .tpl (Besoin d'aide)
Posté : 13 janv. 2016, 03:05
Bonjour, j'ai un petit problème sur mon site, je souhaiterai faire la moyenne de deux attributs (pour l'instant deux mais j'en ai d'autres à ajouter si ça marche) sur une page produit opencart, mais il semble que cela ne soit pas si simple pour l'afficher directement sur la page. Je ne sais pas si je pourrais calculer la moyenne avec ces éléments en php. Si vous avez des idées je suis preneur, je ne trouve pas de solution.
Sans surprise j'ai un message d'erreur, si quelqu'un peut m'aider je suis vraiment nul et je comprend rien à tout ça ! 
Code : Tout sélectionner
<?php
//Note moyenne presse et public
<?php if ($attribute_groups) { ?>
<?php foreach ($attribute_groups as $attribute_group) { ?>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<?php if ($attribute_group['name'] == 'Notation Presse') { ?>
$note1=<?php echo substr($attribute['text'], 0, -4); ?>;
$ref1=<?php echo substr($attribute['text'], -3); ?>;
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
<?php if ($attribute_groups) { ?>
<?php foreach ($attribute_groups as $attribute_group) { ?>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<?php if ($attribute_group['name'] == 'Notation Public') { ?>
$note2=<?php echo substr($attribute['text'], 0, -4); ?>;
$ref2=<?php echo substr($attribute['text'], -3); ?>;
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
//Moyenne des 2 en pourcentage
$moyenne=(+$note1+$note2)*100/(+$ref1+$ref2);
//Resultat note moyenne
echo $moyenne;
?>