【问题标题】:how to handle sequence breaks in db request output如何处理数据库请求输出中的序列中断
【发布时间】:2018-06-29 15:14:27
【问题描述】:

您好,我正在使用基于 Wordpress 的自定义库来管理狗的表演结果。 我的程序当前以整体方式显示结果数组:

如您所见,前 5 列是多条狗共有的。 我想介绍如下顺序中断:

日期位置类型

 Class 1 Judge
    Dog 1
    Dog n
 Total Dogs in Class

 Class 2 Judge
     Dog 1
     Dog n
 Total Dogs in Class
Total Dogs in Show

以下是当前使用的代码(与屏幕截图可能存在一些差异)。

                    foreach ($wpdb->get_results($query)as $row)
                    {
                    print "<tr>";
                    print "<td>" . $row->evt_date . "</td>";
                    print "<td>" . $row->location . "</td>";
                    print "<td>" . $row->type_desc . "</td>";
                    print "<td>" . $row->class_name . "</td>";
                    print "<td>" . $row->civilité . " " . $row->judge_f_name . " " . $row->judge_l_name . "</td>";
                    print "<td>" . $row->position . " " . $row->qualif_descr . "</td>";
                    print "<td>" . $row->dog_name . "</br>" . $row->prod_prop . "</td>";
                    if ($row->CACS_yn == "Y")
                        $distinctions = $distinctions . " CACS ";
                   ...

我只是想了解如何引入序列中断和总计。

【问题讨论】:

    标签: php html arrays wordpress output


    【解决方案1】:

    你可以:

    1. 使用 group by(或 子查询)
    2. 确保您的结果按类、狗排序
    3. 在您的代码中迭代时,您可以跟踪您所使用的类 刚刚检查并查看当前的是否与 上一个。
    4. 在每次迭代时增加一个计数器以获得总次数 节目中的狗。

    【讨论】:

      猜你喜欢
      • 2012-06-01
      • 2017-07-29
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2020-05-03
      • 2011-06-10
      • 2011-02-05
      • 1970-01-01
      相关资源
      最近更新 更多