作業環境が制限されているため、この配列の半分を 1 つのテーブル行に配置し、残りの半分を別の行に配置する必要があります。
これは配列です(すでに必要なものの順にソートされています):
Array
(
[product] => KFE-1221
[description] => Classic Blue
[current_stock] => 630
[purchase_order] =>
[total_sales] => 0
[avail_to_sell] => 630
[size_run1] => 15
[size_run2] => 62
[size_run3] => 122
[size_run4] => 113
[size_run5] => 102
[size_run6] => 92
[size_run7] => 63
[size_run8] => 61
[size_run9] => 0
[size_run10] => 0
)
"size_run1" - "size_run10" の配列を別のテーブル行に分割する必要があります。
以前は、size_run が必要ないときに配列をテーブル (標準の foreach) に表示するためにこれを使用していました。リクエストにより、私はそれを追加しています(そして、はい、非推奨のphpを使用しています)
<?php
while($data = mssql_fetch_assoc($result_ats)) {
if ($data['avail_to_sell'] <= 0){
echo '<tr class="error">';
}
else {
echo '<tr>';
}
foreach($data as $k => $v){
echo '<td>'.$v.'</td>';
echo '</tr>';
}
}
?>
1 つの配列として保持したい理由は、すべての情報に対して 1 つのクエリを使用しているためです。また、使用している巨大なデータベースでは、これをテンプレート側で分割する方が理にかなっています。配列を分離し、製品を size_run に一致させるプロセスを追加します。
配列を異なる配列に分割せずにこれを行う最良の方法は何ですか?
以下のように、配列 '$v' を 2 つの別々のテーブルに分割するという、私の目的の出力:
<tr>
<th>product</th>
<th>description</th>
<th>current_stock</th>
<th>purchase_order</th>
<th>total_sales</th>
<th>avail_to_sell</th>
</tr>
<tr>
<th>size_run1</th>
<th>size_run2</th>
<th>size_run3</th>
<th>size_run4</th>
<th>size_run5</th>
<th>size_run6</th>
<th>size_run7</th>
<th>size_run8</th>
<th>size_run9</th>
<th>size_run10</th>
</tr>