Select optgroup 匹配基于周、日
Select optgroup matches based on week,day
对不起,我的英文不好。
<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>
对不起,我的英文不好。
<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>