Source de Recherche.php
<?php
require('biblimsm.php');
// Connexion à la base
$connexion = mysql_connect(SERVEUR,UTILISATEUR,MOTDEPASSE);
mysql_select_db(NOMBASE,$connexion);
DebutPage('Recherche d\'un lieu dans Lille');
// Définition d'une éventuelle requete
if (isset($type)) {
$requete = "SELECT * FROM lieux AS L, quartiers AS Q, stations AS S, types_lieux AS T
WHERE L.ref_type=$type
AND L.ref_quartier=Q.id
AND L.ref_type=T.id
AND L.ref_metro=S.id
ORDER BY L.nom";
}
if (isset($quartier)) {
$requete = "SELECT * FROM lieux AS L, quartiers AS Q, stations AS S, types_lieux AS T
WHERE L.ref_quartier=$quartier
AND L.ref_quartier=Q.id
AND L.ref_type=T.id
AND L.ref_metro=S.id
ORDER BY L.nom";
}
if (isset($metro)) {
$requete = "SELECT * FROM lieux AS L, quartiers AS Q, stations AS S, types_lieux AS T
WHERE L.ref_metro=$metro
AND L.ref_quartier=Q.id
AND L.ref_type=T.id
AND L.ref_metro=S.id
ORDER BY L.nom";
}
if (isset($motclef)) {
$requete = "SELECT * FROM lieux AS L, quartiers AS Q, stations AS S, types_lieux AS T
WHERE (
L.nom LIKE '%$motclef%'
OR L.adresse LIKE '%$motclef%'
OR L.url LIKE '%$motclef%'
OR L.description LIKE '%$motclef%'
) AND L.ref_quartier=Q.id
AND L.ref_type=T.id
AND L.ref_metro=S.id
ORDER BY L.nom";
}
// Exécution de la requete et affichage des réponses
if (isset($requete)) {
$resultat = mysql_query($requete,$connexion);
$nb_reponses = mysql_num_rows($resultat);
if ($nb_reponses > 0) {
echo "<H2>$nb_reponses réponses à votre recherche</H2>\n";
while ($lieu = mysql_fetch_array($resultat)) {
AfficheLieu($lieu);
}
} else {
echo "<EM>Désolé, aucune réponse à votre recherche...</EM><BR><BR>\n";
}
}
// Sortie du formulaire de recherche
?>
<H2>Par type</H2>
<FORM ACTION="Recherche.php" METHOD="post">
<SELECT NAME="type">
<?php
$requete = "SELECT * FROM types_lieux ORDER BY intitule_type";
$resultat = mysql_query($requete,$connexion);
while ($type = mysql_fetch_array($resultat)) {
echo '<OPTION VALUE="';
echo $type['id'];
echo '"> ';
echo $type['intitule_type'];
echo "\n";
}
?>
</SELECT>
<INPUT TYPE="submit" VALUE="rechercher">
</FORM>
<H2>Par quartier</H2>
<FORM ACTION="Recherche.php" METHOD="post">
<SELECT NAME="quartier">
<?php
$requete = "SELECT * FROM quartiers ORDER BY nom_quartier";
$resultat = mysql_query($requete,$connexion);
while ($quartier = mysql_fetch_array($resultat)) {
echo '<OPTION VALUE="';
echo $quartier['id'];
echo '"> ';
echo $quartier['nom_quartier'];
echo "\n";
}
?>
</SELECT>
<INPUT TYPE="submit" VALUE="rechercher">
</FORM>
<H2>Par station de métro la plus proche</H2>
<FORM ACTION="Recherche.php" METHOD="post">
<SELECT NAME="metro">
<?php
$requete = "SELECT * FROM stations ORDER BY nom_station";
$resultat = mysql_query($requete,$connexion);
while ($station = mysql_fetch_array($resultat)) {
echo '<OPTION VALUE="';
echo $station['id'];
echo '"> ';
echo $station['nom_station'];
echo "\n";
}
?>
</SELECT>
<INPUT TYPE="submit" VALUE="rechercher">
</FORM>
<H2>Sur un mot quelconque</H2>
<FORM ACTION="Recherche.php" METHOD="post">
<INPUT TYPE="text" NAME="motclef">
<INPUT TYPE="submit" VALUE="rechercher">
</FORM>
<?php
mysql_close($connexion);
PiedPage();
?>