• <small id='zDwXP'></small><noframes id='zDwXP'>

  • <i id='zDwXP'><tr id='zDwXP'><dt id='zDwXP'><q id='zDwXP'><span id='zDwXP'><b id='zDwXP'><form id='zDwXP'><ins id='zDwXP'></ins><ul id='zDwXP'></ul><sub id='zDwXP'></sub></form><legend id='zDwXP'></legend><bdo id='zDwXP'><pre id='zDwXP'><center id='zDwXP'></center></pre></bdo></b><th id='zDwXP'></th></span></q></dt></tr></i><div id='zDwXP'><tfoot id='zDwXP'></tfoot><dl id='zDwXP'><fieldset id='zDwXP'></fieldset></dl></div>
    <legend id='zDwXP'><style id='zDwXP'><dir id='zDwXP'><q id='zDwXP'></q></dir></style></legend>
    <tfoot id='zDwXP'></tfoot>

      • <bdo id='zDwXP'></bdo><ul id='zDwXP'></ul>

        对来自 while 循环的记录进行分组 |PHP

        时间:2023-09-20
        <legend id='9MN6M'><style id='9MN6M'><dir id='9MN6M'><q id='9MN6M'></q></dir></style></legend>

        <small id='9MN6M'></small><noframes id='9MN6M'>

                <tbody id='9MN6M'></tbody>
            • <tfoot id='9MN6M'></tfoot>
            • <i id='9MN6M'><tr id='9MN6M'><dt id='9MN6M'><q id='9MN6M'><span id='9MN6M'><b id='9MN6M'><form id='9MN6M'><ins id='9MN6M'></ins><ul id='9MN6M'></ul><sub id='9MN6M'></sub></form><legend id='9MN6M'></legend><bdo id='9MN6M'><pre id='9MN6M'><center id='9MN6M'></center></pre></bdo></b><th id='9MN6M'></th></span></q></dt></tr></i><div id='9MN6M'><tfoot id='9MN6M'></tfoot><dl id='9MN6M'><fieldset id='9MN6M'></fieldset></dl></div>
                  <bdo id='9MN6M'></bdo><ul id='9MN6M'></ul>
                • 本文介绍了对来自 while 循环的记录进行分组 |PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试按优先级对记录进行分组,例如

                  I'm trying to group down records by their priority levels, e.g.

                  --- 优先级:高---

                  记录...

                  --- 优先级:中---

                  记录...

                  --- 优先级:低---

                  记录...

                  类似的事情,我如何在 PHP 中做到这一点?while 循环按具有 int 值(高 = 3,中 = 2,低 = 1)的优先级列对记录进行排序.例如WHERE 优先级 = '1'

                  Something like that, how do I do that in PHP? The while loop orders records by the priority column which has int value (high = 3, medium = 2, low = 1). e.g. WHERE priority = '1'

                  标签:Priority: [priority level]" 必须设置在关于其级别的分组记录之上

                  The label: "Priority: [priority level]" has to be set above the grouped records regarding their level

                  <?php
                  
                  while($row = mysql_fetch_array($result))
                  {
                      echo '<h1>Priority Level: ' . $row['priority'] . '</h1>';
                      echo $row['name'];
                  }
                  
                  ?>
                  

                  就像那段代码一样 -

                  标签是一个标签,用于将记录的优先级分开.

                  Like that piece of code - the

                  tags is the label which seperates records regarding their priority level.

                  推荐答案

                  如果你确定结果是按优先级排序的,那么像下面这样的小事:

                  If you're sure the results are ordered by priority then something as trivial as this:

                  $priority = null;
                  while($row = mysql_fetch_array($result))
                  {
                      if( $row['priority'] != $priority )
                      {
                          echo '<h1>Priority Level: ' . $row['priority'] . '</h1>';
                          $priority = $row['priority'];
                      }
                      echo $row['name'];
                  }
                  

                  换句话说,您在 $priority 变量中跟踪当前的优先级.然后在if条件中测试优先级是否发生了变化.如果是,则echo优先级并将当前优先级设置为当前行中找到的优先级.

                  In other words, you keep track of the current priority level in the $priority variable. Then test whether the priority has changed in the if condition. If so, echo the priority and set the current priority to the priority found in the current row.

                  请注意,如果行按优先级排序,这只会按预期工作(真正分组一次).换句话说,当不同的优先级没有分散在结果集中时.

                  Mind you, this only works as expected (truly grouped once) if the rows are ordered by priority. In other words, when different priorities are not scattered across the resultset.

                  这篇关于对来自 while 循环的记录进行分组 |PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在没有 FETCHALL 的情况下在 MYSQL PDO 中获取 下一篇:虽然循环 PHP get_result 不起作用

                  相关文章

                  最新文章

                      <small id='blEuN'></small><noframes id='blEuN'>

                      • <bdo id='blEuN'></bdo><ul id='blEuN'></ul>

                      <legend id='blEuN'><style id='blEuN'><dir id='blEuN'><q id='blEuN'></q></dir></style></legend>
                      <tfoot id='blEuN'></tfoot>
                    1. <i id='blEuN'><tr id='blEuN'><dt id='blEuN'><q id='blEuN'><span id='blEuN'><b id='blEuN'><form id='blEuN'><ins id='blEuN'></ins><ul id='blEuN'></ul><sub id='blEuN'></sub></form><legend id='blEuN'></legend><bdo id='blEuN'><pre id='blEuN'><center id='blEuN'></center></pre></bdo></b><th id='blEuN'></th></span></q></dt></tr></i><div id='blEuN'><tfoot id='blEuN'></tfoot><dl id='blEuN'><fieldset id='blEuN'></fieldset></dl></div>