1
我打算把一個查詢放到我的變量中,但是我的問題是我需要將不同的一組值分開以將它們分離到我的PHP輸出中我想知道這是否可能,甚至對SQL查詢的幫助也是一大幫助。見我的截圖: 分離表中的行的值
如果你看一下表section
柱的底部,你會看到有一個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
在table
標籤的部分分開? 如何分組不同的值以將它們分離到我的PHP輸出中?任何形式的幫助,將不勝感激。