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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Listes liées</title>
<script type="application/javascript" charset="utf-8" src="http://code.jquery.com/jquery-1.6.3.min.js"></script>
<script type="application/javascript">
function filterLists() {
// ici on récupère les valeurs sélectionnées pour chaque liste avec les sélecteurs de jQuery
var age = $('#ages option:selected').val();
var sexe = $('#sexes option:selected').val();
var metier = $('#metiers option:selected').val();
var metier1 = $('#metiers1 option:selected').val();
// on fait notre appel ajax paramétré (pas besoin de s'occuper de l'implémentation du XMLHttpRequest, jQuery le fait pour toi)
$.ajax({
type: 'POST', // méthode de transmission des données
url: 'filterLists.php', // script à exécuter sur le serveur
data: 'age_='+age+'&sexe='+sexe+'&metier='+metier+'&metier1='+metier1, // données à passer au script via le tableau $_POST
dataType: 'xml', // type des données attendues en retour : ici xml
cache: false,
success: function(response) { // traitement du résultat (= données reçues du serveur) une fois l'appel ajax réussi
var code;
// vu que la réponse est au format xml, on demande à jquery de trouver des noeuds spécifiques
// et si ces noeuds contiennent des données alors on remplace les données des listes liées par celles renvoyées par le serveur
// en clair : on remplace si nécessaire l'ensemble des lignes <option value=""></option> pour chaque liste qui n'a pas encore de sélection
if ((code = $(response).find('ages').text()).length) $('#ages').html(code);
if ((code = $(response).find('sexes').text()).length) $('#sexes').html(code);
if ((code = $(response).find('metiers').text()).length) $('#metiers').html(code);
if ((code = $(response).find('metiers1').text()).length) $('#metiers1').html(code);
if ((code = $(response).find('table').text()).length) $('#table').html(code);
}
});
}
</script>
<style type="text/css">
body { font-family: "arial"; background-color:#000; color:#fff; }
table { width: 600px;}
table, tr, th, td { border: 1px solid black; border-collapse: collapse; padding: 4px;}
.alignr { text-align: right; }
.alignc { text-align: center; }
#flip {
font-size:12px;
padding: 0px;
float:left;
background-color: #000;
}
#panel {
width: 600px;
padding-top: 20px;
display: none;
}
</style>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
</head>
<body>
<?php
// ICI MODIFIEZ LE PARAMETRAGE
// Connexion à la base de données
$server = 'test.mysql.db';
$user = 'test';
$pwd = 'mdp';
$dbName = 'test';
$cnx = mysql_connect($server, $user, $pwd);
$db = mysql_select_db($dbName);
// Au démarrage, aucune sélection : on extrait toutes les données individuellement pour chaque liste
// ages
$sql = 'SELECT DISTINCT t_age.idAge, t_age.age_ FROM t_age ORDER BY t_age.age_;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$ages[$row[0]] = $row[1];
}
// VILLES
$sql = 'SELECT DISTINCT t_sexe.idSexe, t_sexe.sexe FROM t_sexe ORDER BY t_sexe.sexe;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$sexes[$row[0]] = $row[1];
}
// METIERS
$sql = 'SELECT DISTINCT t_metier.idMetier, t_metier.metier FROM t_metier ORDER BY t_metier.metier;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$metiers[$row[0]] = $row[1];
}
// STARS
$sql = 'SELECT DISTINCT t_stars.idStar, t_stars.nom_star FROM t_stars ORDER BY t_stars.nom_star;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {//Retourne une ligne de résultat MySQL sous la forme d'un tableau
$metiers1[$row[0]] = $row[1];
}
// DONNES DE LA TABLE
$sql = <<<SQL
SELECT t_sexe.sexe, t_age.age_, t_metier.metier, t_stars.nom_star, t_age_metier.nbApparition, t_age_metier.bio, t_age_metier.image
FROM t_age_metier
INNER JOIN t_metier ON t_age_metier.idMetier = t_metier.idMetier
INNER JOIN t_age ON t_age_metier.idAge = t_age.idAge
INNER JOIN t_sexe ON t_age.idSexe = t_sexe.idSexe
INNER JOIN t_stars ON t_age_metier.idStar = t_stars.idStar
ORDER BY
t_sexe.sexe ASC,
t_age.age_ DESC,
t_metier.metier ASC,
t_stars.nom_star ASC;
SQL;
$qry = mysql_query($sql) or exit(mysql_error() . "<br/>$qry");
while($row = mysql_fetch_assoc($qry)) {//Lit une ligne de résultat MySQL dans un tableau associatif
$data[] = $row;
}
// pour chaque liste il faut prévoir leur retrait du filtre
// en insérant une ligne vide en début de liste : <option value=""></option>
?>
<?php include("recherche.php"); ?>
<div id="flip">
<img src="images/option.png" alt="options" style="width:20px;height:22px;">Filtrer par critères
</div>
<div id="panel">
<p>Sélectionnez de un à plusieurs critères de recherche.</p>
<form id="frmRecherche">
<!-- Liste des matières -->
<label for="metiers">Métiers</label>
<select id="metiers" onchange="filterLists();">
<option value=""></option>
<?php foreach($metiers as $id => $metier): ?>
<option value="<?php echo $id; ?>"><?php echo $metier; ?></option>
<?php endforeach; ?>
</select>
<!-- Liste des sexes -->
<label for="sexes">Sexe</label>
<select id="sexes" onchange="filterLists();">
<option value=""></option>
<?php foreach($sexes as $id => $sexe): ?>
<option value="<?php echo $id; ?>"><?php echo $sexe; ?></option>
<?php endforeach; ?>
</select>
<!-- Liste des ages -->
<label for="ages">Age</label>
<select id="ages" onchange="filterLists();">
<option value=""></option>
<?php foreach($ages as $id => $age_): ?>
<option value="<?php echo $id; ?>"><?php echo $age_; ?></option>
<?php endforeach; ?>
</select>
</form>
<!-- Données de la table -->
<table>
<tr>
<th>BIO</th>
<th>PHOTO</th>
</tr>
<tbody id="table">
<?php foreach($data as $row):
if (ISSET($_POST["metier"])) { echo $row['metier'];}
if (ISSET($_POST["sexe"])) { echo $row['sexe'];}
if (ISSET($_POST["age_"])) { echo $row['age_'];}
if (ISSET($_POST["bio"])) {echo $row['bio'];}
if (ISSET($_POST["image"])) {echo"<img src='".$row['image']."' />";}
// if (ISSET($_POST["nbApparition"])) {echo $row['nbApparition'];}
endforeach; ?>
</tbody>
</table>
</div>
</body>
</html> |
Partager