【问题标题】:Group By word count fore conversion table Laravel 5.3Group By 字数转换表 Laravel 5.3
【发布时间】:2016-10-10 17:33:52
【问题描述】:

我需要计算每个特定类别中有多少单词。因此,例如,就我而言,我现在正在这样做以计算特定列表中的单词数。

@if (str_word_count($stats->description) < 250)
     0 - 249
@elseif(str_word_count($stats->description) >= 250 && str_word_count($stats->description) <= 500)
    250 - 500
@elseif(str_word_count($stats->description) >=  501 && str_word_count($stats->description) <= 750)
    500 - 750
@else
    750+
@endif

最后我有一张表,我需要按每个类别计算。像这样:

<table class="table table-condensed table-responsive">
                        <thead>
                            <tr>
                                <th class="text-center" colspan="6">Conversion Rate For Word Count</th>
                            </tr>
                            <tr>
                                <th>0 - 249 words</th>
                                <th>250 - 500 words</th>
                                <th>500 - 750 words</th>
                                <th>750 + words</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                        </tbody>
                    </table>

我将如何计算所有包含 0 -249 个单词等的列表?

【问题讨论】:

    标签: php laravel laravel-5.3


    【解决方案1】:

    这样的东西对你有用吗?

    PHP

    $counts = ['0-249'=>0, '250-499'=>0, '500-749'=>0, '750+'=>0];
    @if (str_word_count($stats->description) < 250)
         $counts['0-249']++;
    @elseif(str_word_count($stats->description) >= 250 && str_word_count($stats->description) <= 500)
        $counts['250-499']++;
    @elseif(str_word_count($stats->description) >=  501 && str_word_count($stats->description) <= 750)
        $counts['500-749']++;
    @else
        $counts['750+']++;
    @endif
    

    HTML

                    <table class="table table-condensed table-responsive">
                        <thead>
                            <tr>
                                <th class="text-center" colspan="6">Conversion Rate For Word Count</th>
                            </tr>
                            <tr>
                                <th>0 - 249 words</th>
                                <th>250 - 499 words</th>
                                <th>500 - 749 words</th>
                                <th>750 + words</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><?php echo $counts['0-249']; ?></td>
                                <td><?php echo $counts['250-499']; ?></td>
                                <td><?php echo $counts['500-749']; ?></td>
                                <td><?php echo $counts['750+']; ?></td>
                            </tr>
                        </tbody>
                    </table>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 2022-01-23
      • 2021-03-30
      • 2018-01-28
      • 1970-01-01
      相关资源
      最近更新 更多