Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Joomla Rating,显示%i希望它查看&x27;8.2/10';?_Php_Joomla_Rating System_Joomla K2 - Fatal编程技术网

Php Joomla Rating,显示%i希望它查看&x27;8.2/10';?

Php Joomla Rating,显示%i希望它查看&x27;8.2/10';?,php,joomla,rating-system,joomla-k2,Php,Joomla,Rating System,Joomla K2,我正在使用组件K2,以及它的投票/评级系统。目前,它以百分比的形式显示评级,并使用一些css来查看星星。但是,我不想显示星星,而是想让它显示,例如,4.5/5 这是查看它的代码: <?php if($this->item->params->get('catItemRating')): ?> <div id="catItemRatingBlock"> <div class="itemRatingForm"> <ul class="

我正在使用组件K2,以及它的投票/评级系统。目前,它以百分比的形式显示评级,并使用一些css来查看星星。但是,我不想显示星星,而是想让它显示,例如,4.5/5

这是查看它的代码:

<?php if($this->item->params->get('catItemRating')): ?>
<div id="catItemRatingBlock">
 <div class="itemRatingForm">
   <ul class="itemRatingList">
     <li class="itemCurrentRating" id="itemCurrentRating<?php echo $this->item->id; ?>" style="width:<?php echo $this->item->votingPercentage; ?>%;"></li>
     <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="one-star">1</a></li>
     <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="two-stars">2</a></li>
     <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="three-stars">3</a></li>
     <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="four-stars">4</a></li>
     <li><a href="#" rel="<?php echo $this->item->id;  ?>" class="five-stars">5</a></li>
   </ul>
 </div>
</div>
<?php endif; ?>

我该怎么办?

总之,取下列所示百分比:$this->item->votingPercentage(0到100),然后将其除以20,将其转换为0到5范围内的数字。在将数字显示为5中的x时,您可能希望保留1位小数

因为您不知道votingPercentage是字符串还是数字,所以在进行任何计算之前,我会测试它以确保它具有有效的数值:

<?php

if (!isnumeric($this->item->votingPercentage) {

   $numericRating = 0;

// If the value cannot be interpreted as a numeric, we assume a value of 0.

}

else {

   $numericRating = round(($this->item->votingPercentage / 2), 0);  

// The statement above is equivalent to dividing the percentage by 20 (to get a number from 0 to 5); and then multiplying by 10 to get a number from 0 to 50.  Since this final number could have a decimal component (for example 42.55 out of 50), we round to 0 decimal places to get rid of the decimal remainder - in this example, resulting in the number 43

   $numericRating = round(($numericRating / 10), 1);

// The statement above divides the number from the previous step by 10 (to shift the decimal point), and just for good measure, applies the rounding function one more time in case the division yields a number like 4.300000001 or 4.29999999

}

echo $numericRating . "/5";

// Finally, the resulting numeric value is rendered as a number from 0 to 5 with 1 decimal place, followed by the characters "/5"  (i.e. out of 5)
?>

当您在K2中编辑一篇文章时,它们会显示您在后端描述的文章评级。右侧的侧栏显示为
(平均评级:5.00/5.00)
。看看他们在那里使用的代码。快告诉我,安。玩得好,这是一个非常彻底的答案。
<?php

if (!isnumeric($this->item->votingPercentage) {

   $numericRating = 0;

// If the value cannot be interpreted as a numeric, we assume a value of 0.

}

else {

   $numericRating = round(($this->item->votingPercentage / 2), 0);  

// The statement above is equivalent to dividing the percentage by 20 (to get a number from 0 to 5); and then multiplying by 10 to get a number from 0 to 50.  Since this final number could have a decimal component (for example 42.55 out of 50), we round to 0 decimal places to get rid of the decimal remainder - in this example, resulting in the number 43

   $numericRating = round(($numericRating / 10), 1);

// The statement above divides the number from the previous step by 10 (to shift the decimal point), and just for good measure, applies the rounding function one more time in case the division yields a number like 4.300000001 or 4.29999999

}

echo $numericRating . "/5";

// Finally, the resulting numeric value is rendered as a number from 0 to 5 with 1 decimal place, followed by the characters "/5"  (i.e. out of 5)
?>