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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
| <?php
// Au démarrage, aucune sélection : on extrait toutes les données individuellement pour chaque liste
// Tu as 4 listes : Raison sociale | ROS | Code postal | Produit
mysql_connect('localhost', 'root', '');
mysql_select_db('xls_db');
// raison sociale
$sql = 'SELECT DISTINCT client FROM histo ORDER BY client';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataClient[] = $row['client']; // à la place de $dataClient[] = $row[];
}
// ROS
$sql = 'SELECT DISTINCT ros FROM histo ORDER BY ros';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataRos[] = $row['ros']; // à la place de $dataRos[] = $row[];
}
// code postal
$sql = 'SELECT DISTINCT codepostal FROM histo ORDER BY codepostal';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataCp[] = $row['codepostal']; // à la place de $dataCp[] = $row[];
}
// produit
$sql = 'SELECT DISTINCT id_produit FROM histo ORDER BY id_produit';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataProduit[] = $row['id_produit']; // à la place de $dataProduit[] = $row[];
}
// historique non filtré
// produit
$sql = 'SELECT * FROM histo';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataHisto[] = $row; // à la place de $dataHisto[] = $row[];
}
$hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES); }
?>
<!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>Projet ROS</title>
<script type="application/javascript" charset="ISO-8859-1" 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 client = $('#clients option:selected').val();
var ros = $('#ros option:selected').val();
var cp = $('#cps option:selected').val();
var produit = $('#produits 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: 'client='+client+'&ros='+ros+'&cp='+cp+'&produit='+produit, // 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('clients').text()).length) $('#clients').html(code);
if ((code = $(response).find('ros').text()).length) $('#ros').html(code);
if ((code = $(response).find('cps').text()).length) $('#cps').html(code);
if ((code = $(response).find('produits').text()).length) $('#produits').html(code);
if ((code = $(response).find('table').text()).length) $('#table').html(code);
}
});
}
</script>
<style type="text/css">
body { font-family: "arial"; }
table { width: 600px;;}
table, tr, th, td { border: 1px solid black; border-collapse: collapse; padding: 4px;}
.alignr { text-align: right; }
.alignc { text-align: center; }
</style>
</head>
<body>
<?php
// ICI MODIFIEZ LE PARAMETRAGE
// Connexion à la base de données
$server = 'localhost';
$user = 'root';
$pwd = '';
$dbName = 'xls_db';
$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
// CLIENTS
$sql = 'SELECT DISTINCT histo.client FROM histo ORDER BY histo.client;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$dataClient[] = $row[0]; // à la place de $dataClient[] = $row[0];
}
// ROS
$sql = 'SELECT DISTINCT histo.ros FROM histo ORDER BY histo.ros;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$dataRos[] = $row[0]; // à la place de $dataRos[] = $row[0];
}
// CODEPOSTAL
$sql = 'SELECT DISTINCT histo.codepostal FROM histo ORDER BY histo.codepostal;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$dataCp[] = $row[0]; // à la place de $dataCp[] = $row[0];
}
// PRODUITS
$sql = 'SELECT DISTINCT histo.id_produit FROM histo ORDER BY histo.id_produit;';
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$dataProduit[] = $row[0]; // à la place de $dataProduit[] = $row[0];
}
// DONNES DE LA TABLE
$sql = <<<SQL
SELECT histo.id_produit, histo.type_produit, histo.ros, histo.client, histo.adresse, histo.ville, histo.codepostal
FROM histo
ORDER BY
histo.id_produit ASC,
histo.type_produit ASC,
histo.ros ASC,
histo.client ASC,
histo.adresse ASC,
histo.ville ASC,
histo.codepostal ASC
SQL;
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$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>
?>
<p><strong>PROJET ROS</strong></p>
<p>Sélectionnez de un à plusieurs critères de recherche.</p>
<form id="frmRecherche">
<!-- Liste des clients -->
<label for="clients">Clients</label>
<select id="clients" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataClient as $client): ?>
<option value="<?php echo $hsc($client); ?>"><?php echo $hsc($client); ?></option>
<?php endforeach; ?>
</select>
<!-- Liste des ROS-->
<label for="ros">ROS</label>
<select id="ros" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataRos as $ros): ?>
<option value="<?php echo $hsc($ros); ?>"><?php echo $hsc($ros); ?></option>
<?php endforeach; ?>
</select>
<!-- Liste des codes postaux-->
<label for="cp">Code Postal</label>
<select id="cp" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataCp as $cp): ?>
<option value="<?php echo $hsc($cp); ?>"><?php echo $hsc($cp); ?></option>
<?php endforeach; ?>
</select>
<!-- Liste des produits-->
<label for="produit">Produits</label>
<select id="produit" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataProduit as $produit): ?>
<option value="<?php echo $hsc($produit); ?>"><?php echo $hsc($produit); ?></option>
<?php endforeach; ?>
</select>
</form>
<!-- Données de la table -->
<table>
<thead>
<tr>
<th>Produit</th>
<th>Type</th>
<th>ROS</th>
<th>Client</th>
<th>Adresse</th>
<th>Ville</th>
<th>CP</th>
</tr>
</thead>
<tbody id="table">
<?php foreach($dataHisto as $row): ?>
<tr>
<td><?php echo $hsc($row['id_produit']); ?></td>
<td><?php echo $hsc($row['type_produit']); ?></td>
<td><?php echo $hsc($row['ros']); ?></td>
<td><?php echo $hsc($row['client']); ?></td>
<td><?php echo $hsc($row['adresse']); ?></td>
<td><?php echo $hsc($row['ville']); ?></td>
<td><?php echo $hsc($row['codepostal']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html> |
Partager