A mon avis, là tu te fais du mal.
Utilise un for !
Code :<form>
<select onchange="location = this.options[this.selectedIndex].value">
<?php for ($i = 0; $i < 8; ++$i) {
$u = sprintf('fiche.php?a=%d', $i);
if ($i) {
?><option value="<?php echo $u; ?>"<?php if ($a == "") {?> selected="selected"<?php } ?>>Selectionner une peche</option><?php
} else {
?><option value="<?php echo $u; ?>"<?php if ($a == $i) {?> selected="selected"<?php } ?>><?php echo $i; ?></option><?php
}
?>
</select>
</form>
Personnellement, je réfléchirai à faire générique avant d'envisager une solution technique.
La question qui se pose c'est d'où viennent tes données?
1) base de données? dans ce cas, ton switch est un mauvais départ
2) données statiques? dans ce cas, je te suggère de transformer ce "statique" en statique mais sans code métier/d'affichage, genre:
ie:
Code :<?php
$data = array(
1 => array(
'title' => 'Titre',
'content' => array(
2 => array(
'title' => 'Titre',
'content' => array(
3 => array(
'title' => 'foobar',
),
),
),
),
);
function write_select(array $data, $selected, $url, $disabledText) {
?><select onchange="window.location.href = this.options[this.selectedIndex].value">
<option<?php if ($selected === null || !isset($data[$selected])) {?> selected="selected"<?php } ?><?php echo $disabledText; ?></option>
<?php foreach ($data as $c as $d) {?>
<option value="<?php printf($url, $c) ?>"<?php if ($c == $selected) {?> selected="selected"<?php } ?>><?php echo $d['title']; ?></option>
<?php }?></select><?php
}
$a = isset($_GET['a']) ? intval($_GET['a']):null;
$b = isset($_GET['b']) ? intval($_GET['b']):null;
$c = isset($_GET['c']) ? intval($_GET['c']):null;
// écriture contenu
?><form><?php
write_select($data, $a, 'fiche.php?a=%d', 'Sélectionner une pêche');
if ($a !== null && isset($data[$a])) {
write_select($data[$a], $b, 'fiche.php?a=' . $a . '&b=%d', 'Sélectionner une materiel');
if ($b !== null && isset($data[$a][$b])) {
write_select($data[$a][$b], $c, 'fiche.php?a=' . $a . '&b=' . $b . '&c=%d', '?');
}
}
?></form>
Si tu as pigé ce code, alors je pense que tu comprendras ce que je veux dire. En tout cas, ça devrait déjà te simplifier la vie