-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecherches.php
65 lines (56 loc) · 3.08 KB
/
recherches.php
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
<h2>Recherche de biens</h2>
<form action="index.php?p=recherches" method="post">
<form action="index.php?p=recherches" method="post">
<INPUT type=text name="rech" <?php if(isset($_POST['rech'])) {echo 'value="'.$_POST['rech'].'" ';} ?>>
<INPUT name="bouton" type="submit" value="Rechercher">
</form>
<?php
if(isset($_POST['bouton'])) {
echo '<h2>Biens trouvés</h2>';
if (COUNT(explode(" ", $_POST["rech"]))>3) {echo "<p>Vous avez saisie trop de mot.</p>";}
else {
$exp = array();
$exp = explode(" ", $_POST["rech"]);
$req="(SELECT idbien, detailbien, photobien FROM bien";
if (COUNT(explode(" ", $_POST["rech"]))==1) {$req=$req." WHERE detailbien LIKE '%".$exp[0]."%');";}
elseif (COUNT(explode(" ", $_POST["rech"]))==2) {$req=$req." WHERE detailbien LIKE '%".$exp[0]."%' AND detailbien LIKE '%".$exp[1]."%')
UNION (SELECT idbien, detailbien, photobien FROM bien WHERE detailbien LIKE '%".$exp[0]."%' OR detailbien LIKE '%".$exp[1]."%');";}
elseif (COUNT(explode(" ", $_POST["rech"]))==3) {$req=$req." WHERE detailbien LIKE '%".$exp[0]."%' AND detailbien LIKE '%".$exp[1]."%' AND detailbien LIKE '%".$exp[2]."%')
UNION (SELECT detailbien, photobien FROM produit WHERE detailbien LIKE '%".$exp[0]."%' AND detailbien LIKE '%".$exp[1]."%' OR detailProd LIKE '%".$exp[1]."%'
AND detailbien LIKE '%".$exp[2]."%' OR detailbien LIKE '%".$exp[0]."%' AND detailbien LIKE '%".$exp[2]."%')
UNION (SELECT idbien, detailbien, photobien FROM produit WHERE detailbien LIKE '%".$exp[0]."%' OR detailbien LIKE '%".$exp[1]."%'
OR detailbien LIKE '%".$exp[2]."%');";}
$req=mysql_query($req) or die('Erreur select : '.mysql_error());
// Ajout mot saisie en gras
$replacements = array();
$patterns = array(); // la chaine que je cherche a etre remplacée (ici detailbien)
$j=0;
while ($j<count($exp)){
$patterns[] = ".$exp[$j]."; //on met les mots à remplacer dans patterns
$replacements[] = " <b> " . $exp[$j] . " </b> "; // on les remplace
$j++;
}
if (mysql_num_rows($req)==0) {echo 'Aucun bien trouvé...';}
else {
echo '<center><table border=1><tr><th>Image</th><th>Détail du bien</th><th></th></tr>';
while($data=mysql_fetch_array($req)) {
$data["detailbien"] = preg_replace($patterns, $replacements, $data["detailbien"]);
echo '<tr><td><img src="images/'.$data["photobien"].'" \></td><td>'.$data["detailbien"].'</td>
<td><form action="index.php?p=ajoutvisites&idbien='.$data["idbien"].'" method="post">
<select name="prio" >
<option value="1" > Intéressé au plus haut point ! </option>
<option value="2" > Très intéressé </option>
<option value="3" > intéressé </option>
<option value="4" > Peu intéressé </option>
<option value="5" > Très peu intéressé </option>
</select>
<input name="visiter" value="visiter" type="submit" /></form></td>
</tr>';
}
echo '</table></center>';
}
}
}
mysql_close();
?>
</form>