抱歉,标题不好,我的英语不好。
<select class="chosen2" name="mac" onchange="this.form.submit()">
<option></option>
<?php
error_reporting(0);
$maclist = mysql_query("SELECT year,split,leagueid,takim,versus,mac,week,day
FROM league WHERE id >= 0 $ligsarry $yearsarrf $splitsarrf GROUP by mac ORDER BY hafta desc,gun desc,mac desc,side asc, id asc");
while ($macs=mysql_fetch_array($maclist)) {
?>
<option <?php if (isset($_GET['mac']) && $_GET['mac']==$macs['mac']) {echo "selected='selected'"; } ?> value="<?php echo $macs['mac']; ?>"><?php echo $macs['mac'] . " -- W" . $macs['week'] . "D" . $macs['day'];;?></option>
<?php }?>
</select>
我用这段代码得到了这个结果:
我要添加<optgroup label="Week 1 Day 2"> -w1d2 matches- </optgroup>
和<optgroup label="Week 1 Day 1"> -w1d1 matches- </optgroup>
但我不知道该怎么做。一天的比赛次数并不总是 4 场。
最佳答案
我认为这应该有效:
$current_day = 0;
while (...) {
if ($macs['day'] != $current_day) {
if ($current_day > 0) {
print '</optgroup>';
}
print '<optgroup>';
$current_day = $macs['day'];
}
print '<option>...</option>';
}
if ($current_day > 0) {
print '</optgroup>';
}
每次您阅读新的 $macs['day']
然后打印 <optgroup>
关于php - 根据周、日选择 optgroup 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36377321/