1 回答
TA贡献2065条经验 获得超13个赞
所以你会:
循环每个单独的子数组。
ukuran_terkecil
从和获取最小值和最大值ukuran_terbesar
。计算实际最大值为
ukuran_terkecil
+ 7(不包括关闭)。ukuran_terkecil
从到+ 7逐一迭代ukuran_terkecil
。如果
ukuran_terbesar
变得小于$i
(您的循环变量),则打印0
这些值。
片段:
<?php
foreach($data as $values){
$min = intval($values['ukuran_terkecil']);
$max = intval($values['ukuran_terbesar']);
$new_max = $min + 7;
echo "ID => ",$values['id'],"<br/>";
echo "Size => ";
for($i = $min; $i < $new_max; ++$i){
if($i > $max) echo " 0";
else echo " ",$i;
}
echo "<br/><hr>";
}
完整代码:(包括数组数据)
<?php
$data = array (
0 =>
array (
0 => '0C529E7D34AE7196',
'id' => '0C529E7D34AE7196',
1 => '0',
'stoksatu' => '0',
2 => '0',
'stokdua' => '0',
3 => '2',
'stoktiga' => '2',
4 => '2',
'stokempat' => '2',
5 => '2',
'stoklima' => '2',
6 => '1',
'stokenam' => '1',
7 => '2',
'stoktujuh' => '2',
8 => '2C2C243A1C7A',
'warna' => '2C2C243A1C7A',
9 => '37',
'ukuran_terkecil' => '37',
10 => '43',
'ukuran_terbesar' => '43',
11 => 'hugob026.png',
'foto' => 'hugob026.png',
12 => 'SpHu26Co.png',
'qrcode' => 'SpHu26Co.png',
13 => '3A340C6CF62780C7',
'nama_model' => '3A340C6CF62780C7',
14 => '0C52CCD7EDB3',
'nama_merk' => '0C52CCD7EDB3',
),
1 =>
array (
0 => '281E300870803B0E',
'id' => '281E300870803B0E',
1 => '2',
'stoksatu' => '2',
2 => '2',
'stokdua' => '2',
3 => '2',
'stoktiga' => '2',
4 => '1',
'stokempat' => '1',
5 => '0',
'stoklima' => '0',
6 => '0',
'stokenam' => '0',
7 => '0',
'stoktujuh' => '0',
8 => '3A0C5ADCC9',
'warna' => '3A0C5ADCC9',
9 => '24',
'ukuran_terkecil' => '24',
10 => '27',
'ukuran_terbesar' => '27',
11 => '3.PNG',
'foto' => '3.PNG',
12 => 'ArSaeeHi.png',
'qrcode' => 'ArSaeeHi.png',
13 => '0C70AE351850C0',
'nama_model' => '0C70AE351850C0',
14 => '281E5EC4FB9763',
'nama_merk' => '281E5EC4FB9763',
),
2 =>
array (
0 => '222C60825DE2FF870572',
'id' => '222C60825DE2FF870572',
1 => '1',
'stoksatu' => '1',
2 => '1',
'stokdua' => '1',
3 => '2',
'stoktiga' => '2',
4 => '1',
'stokempat' => '1',
5 => '2',
'stoklima' => '2',
6 => '0',
'stokenam' => '0',
7 => '0',
'stoktujuh' => '0',
8 => '3A0C5ADCC979F88965B6',
'warna' => '3A0C5ADCC979F88965B6',
9 => '40',
'ukuran_terkecil' => '40',
10 => '44',
'ukuran_terbesar' => '44',
11 => 'IMG-20190428-WA0018.jpg',
'foto' => 'IMG-20190428-WA0018.jpg',
12 => 'DaItyyHiPi.png',
'qrcode' => 'DaItyyHiPi.png',
13 => '38327AAC01',
'nama_model' => '38327AAC01',
14 => '222C2A262404',
'nama_merk' => '222C2A262404',
),
);
foreach($data as $values){
$min = intval($values['ukuran_terkecil']);
$max = intval($values['ukuran_terbesar']);
$new_max = $min + 7;
echo "ID => ",$values['id'],"<br/>";
echo "Size => ";
for($i = $min; $i < $new_max; ++$i){
if($i > $max) echo " 0";
else echo " ",$i;
}
echo "<br/><hr>";
}
更新:
您的 SQL while 循环如下所示,逐行打印大小:
<?php
while ($y=mysqli_fetch_array($t)) {
$mrk = implode("", DekripCBC($y['nama_merk']));
$mdl = implode("", DekripCBC($y['nama_model']));
$wr = implode("", DekripCBC($y['warna']));
$no++;
$sizes = [];
$min = intval($y['ukuran_terkecil']);
$max = intval($y['ukuran_terbesar']);
$new_max = $min + 7;
for($i = $min; $i < $new_max; ++$i){
if($i > $max) $sizes[] = 0;
else $sizes[] = $i;
}
echo "
<tr>
<td>$no</td>
<td>$mrk $mdl $wr<br><br>
<img src=view/foto_sepatu/$y[foto] width=140px>
</td>
<td>".implode("<br/>",$sizes)."</td>
<td>$y[stoksatu]<br> $y[stokdua]<br>$y[stoktiga]<br>$y[stokempat]<br>$y[stoklima]<br>$y[stokenam]<br>$y[stoktujuh]</td>
</tr>
";
}
- 1 回答
- 0 关注
- 107 浏览
添加回答
举报