1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<?php
function creeListe($entete,$info,$array,$elementsCoches) {?>
<tr>
<td><?php print $entete;?></td>
</tr>
<?php
foreach($array as $key => $value) {
$checked = in_array($value,$elementsCoches) ? "checked" : "";?>
<tr>
<td>
<input type="checkbox" class="<?php print $info;?>" name="<?php print $info.'[]';?>" value="<?php print $value;?>" <?php print $checked;?> />
<?php print $value;?>
</td>
</tr><?php
}
}
$marquesCochees = array();
if (isset($_POST['marque'])) {
$marquesCochees = $_POST['marque'];
}
$carburantsCoches = array();
if (isset($_POST['carburant'])) {
$carburantsCoches = $_POST['carburant'];
}
$fichier = 'voitures.xml';
$xml = simplexml_load_file($fichier);
$arrMarque = array();
$arrModele = array();
$arrCarbur = array();
// je fais le fainéant en ne testant pas l'existence dans le tableau avant
foreach($xml as $wature){
$arrMarque[] = trim($wature->marque);
$arrModele[] = trim($wature->modele);
$arrCarbur[] = trim($wature->carburant);
}
$arrMarque = array_unique($arrMarque);
$arrModele = array_unique($arrModele);
$arrCarbur = array_unique($arrCarbur);
natsort($arrMarque);
natsort($arrModele);
natsort($arrCarbur);
?>
<table id="tableau">
<tr>
<td>Filtres</td>
</tr>
<?php
creeListe("Marque","marque",$arrMarque,$marquesCochees);
creeListe("Carburant","carburant",$arrCarbur,$carburantsCoches);
?>
</tr>
</table> |