Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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 分隔表中行的值_Php_Mysql_Yii2 - Fatal编程技术网

Php 分隔表中行的值

Php 分隔表中行的值,php,mysql,yii2,Php,Mysql,Yii2,我计划将一个查询放入我的变量中,但我的问题是我需要将一组不同的值分组,以便在我的PHP输出中将它们分开。我想知道这是否可行,即使对SQL查询有帮助也会有很大帮助。请参见我的屏幕截图: 如果您查看表格部分列的底部,您将看到一个GI21和GI122。我现在使用的查询是这样的 SELECT `scstock`.*, `schead`.* FROM `scstock` LEFT JOIN `schead` ON schead.TrNo = scstock.TrNo WHERE (`schead`.`c

我计划将一个查询放入我的变量中,但我的问题是我需要将一组不同的值分组,以便在我的PHP输出中将它们分开。我想知道这是否可行,即使对SQL查询有帮助也会有很大帮助。请参见我的屏幕截图:

如果您查看表格
部分
列的底部,您将看到一个
GI21
GI122
。我现在使用的查询是这样的

SELECT `scstock`.*, `schead`.* FROM `scstock` LEFT JOIN `schead` ON schead.TrNo = scstock.TrNo WHERE (`schead`.`curriculumcode`='BSIT 2011') AND (`schead`.`styear`='4') AND (`schead`.`terms`='1ST') AND (`schead`.`isBlock`=1)
还是用Yii

->select(['scstock.*', 'schead.*'])
    ->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
    ->where(['schead.curriculumcode' => $curriculumcode,
              'schead.styear' => $year,
              'schead.terms' => $term,
              'schead.isBlock' => 1
              ])
    ->asArray()
    ->all();
这将输出所有行,这些行具有
isBlock=1
,但我需要做的是分离
GI21
GI122
,可能现在就将它们放在一个数组中,但可能有更好的实现,但现在在将它们放在一个数组中之后,我返回它们,将它们放在这样一个表的视图中

 <table class="table table-bordered" id="studentTable">
              <th>Subject</th>
              <th>Schedule</th>
              <th>Section</th>
              <th>Action</th>
              <th>Slots</th>
              <th>Status</th>
          <?php foreach($getBlock as $values): ?>

                  <tr>
                    <td><?= $values['subjectcode']; ?></td>
                    <td><?= $values['schedday'] . ' ' . $values['schedtime'] ?></td>
                    <td><?= $values['section'] ?></td>
                    <td><?= '....' ?></td>
                    <td><?= $values['slots'] ?></td>
                    <td><?= '....' ?></td>
                  </tr>

          <?php endforeach; ?>
              </table>

主题
日程
部分
行动
槽
地位

现在要在视图中分离它们,也许我只需将
foreach
放在
表中
标记来分离部分?如何将不同的一组值分组以在PHP输出中分离它们?任何类型的帮助都将不胜感激。

您可以使用两个单独的查询,一个用于not(G121和GI122)例如:getBlock1

->select(['scstock.*', 'schead.*'])
    ->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
    ->where(['schead.curriculumcode' => $curriculumcode,
              'schead.styear' => $year,
              'schead.terms' => $term,
              'schead.isBlock' => 1,
              'not in','schead.section',['G121', 'GI122'],
              ])
    ->asArray()
    ->all();
第二个是in(G121和GI122),例如:getBlock2

where(['not in','attribute',$array]);



->select(['scstock.*', 'schead.*'])
    ->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
    ->where(['schead.curriculumcode' => $curriculumcode,
              'schead.styear' => $year,
              'schead.terms' => $term,
              'schead.isBlock' => 1,
              'in','schead.section',['G121', 'GI122'],
              ])
    ->asArray()
    ->all();

您可以在第一个foreach中关联到$getBlock1,在第二个foreach中关联到$getBlock2,您可以使用两个单独的查询,一个用于not(G121和GI122),例如:getBlock1

->select(['scstock.*', 'schead.*'])
    ->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
    ->where(['schead.curriculumcode' => $curriculumcode,
              'schead.styear' => $year,
              'schead.terms' => $term,
              'schead.isBlock' => 1,
              'not in','schead.section',['G121', 'GI122'],
              ])
    ->asArray()
    ->all();
where(['not in','attribute',$array]);



->select(['scstock.*', 'schead.*'])
    ->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
    ->where(['schead.curriculumcode' => $curriculumcode,
              'schead.styear' => $year,
              'schead.terms' => $term,
              'schead.isBlock' => 1,
              'in','schead.section',['G121', 'GI122'],
              ])
    ->asArray()
    ->all();
第二个是in(G121和GI122),例如:getBlock2

where(['not in','attribute',$array]);



->select(['scstock.*', 'schead.*'])
    ->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
    ->where(['schead.curriculumcode' => $curriculumcode,
              'schead.styear' => $year,
              'schead.terms' => $term,
              'schead.isBlock' => 1,
              'in','schead.section',['G121', 'GI122'],
              ])
    ->asArray()
    ->all();
您可以在第一个foreach中关联$getBlock1,在第二个foreach中关联$getBlock2

where(['not in','attribute',$array]);



->select(['scstock.*', 'schead.*'])
    ->leftJoin('schead', 'schead.TrNo = scstock.TrNo')
    ->where(['schead.curriculumcode' => $curriculumcode,
              'schead.styear' => $year,
              'schead.terms' => $term,
              'schead.isBlock' => 1,
              'in','schead.section',['G121', 'GI122'],
              ])
    ->asArray()
    ->all();