douli1306 2019-03-22 11:39
浏览 55
已采纳

PHP - 定价表 - 价格是免费的

i have Price tables with monthly and yearly costs but i need a price table there is for free access. If i set the Price to Zero i get an error coz the code cant read the zero price. Below the code snippet. thanks

<?php foreach ($Packages->getDataAs("Package") as $p): ?>
                    <div class="price">
                        <div class="price-content">
                            <div class="main-price">
                                <h1><?= format_price($p->get("monthly_price")) ?></h1>
                                <p><?= htmlchars($Settings->get("data.currency")) ?>/<?= __("per month") ?></p>
                            </div>

                            <p class="special-discount">
                                <?php
                                    $total = 12 * $p->get("monthly_price");
                                    $dif = $total - $p->get("annual_price");
                                    $save = $dif * 100 / $total;

                                    if ($save > 0) {
                                        echo __("Save %s when paid annualy", format_price($dif) . " " . htmlchars($Settings->get("data.currency")));
                                    }
                                ?>
                            </p>
  • 写回答

1条回答 默认 最新

  • duanfu3390 2019-03-22 12:14
    关注

    Adding this will solve your problem

    $total = 12 * $p->get("monthly_price");
    $dif = $total - $p->get("annual_price");
    if($total > 0)  //Omits Divide by zero exception
       $save = $dif * 100 / $total;
    else
       $save = 0;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探