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
|
<?php
//S'il y a ou pas des résultats à afficher
if($reponse -> rowCount() > 1)
{
echo '<table style="width:451px">
<tr>
<td style="background-color:#000000;border:1px #000000 solid;text-align:center;vertical-align:top;width:150px;height:13px"><span style="color:#FFFFFF;font-family:Arial;font-size:12px;">Article</span></td>
<td style="background-color:#000000;border:1px #000000 solid;text-align:center;vertical-align:top;width:214px;height:13px"><span style="color:#FFFFFF;font-family:Arial;font-size:12px;">Résumé</span></td>
<td style="background-color:#000000;border:1px #000000 solid;text-align:center;vertical-align:top;width:65px;height:13px"><span style="color:#FFFFFF;font-family:Arial;font-size:12px;">Disponibilité</span></td>
<td><img src="../images/option.gif" width="13" height="13"> </td>
</tr>';
}
else
{
echo 'pas de données';
}
//recherche des mots clés enregistr
$reponse = $session->query("SELECT article FROM list WHERE id_session = '$mon_id'");
while ($donnees = $reponse->fetch())
{
//tableau des données de la recherche
$recherche[] = $donnees['article'];
}
$expressions = array();
//On determine le type de recherche
if(isset($_GET['type']))
{
if($_GET['type']=='un')//Un des mots
{
$type = 1;
}
elseif($_GET['type']=='tout')//Tout les mots
{
$type = 2;
}
else//L'expression exacte
{
$type = 3;
}
}
else
{
//type par defaut: L'expression exacte
$req_type = $session->query("SELECT type FROM membres WHERE id = $mon_id ");
$result_type = $req_type -> fetch();
$type = $result_type['type'];
}
$operateur = ($type == 1) ? ' OR ' : ' AND ';
if ($type == 1 || $type == 2) { // pour les type 1 et 2 on découpe chaque mot
foreach($recherche as $mots)
{
$expressions = array_merge($expressions, explode(' ', $mots));
}
}
else
{ // pour le type 3 on cherche le texte entier
$expressions = $recherche;
}
//On determine si on doit surligner les mots dans les resultats
if(!isset($_GET['surligner']) or $_GET['surligner']!='true')
{
$surligner = false;
}
else
{
$surligner = true;
}
var_dump($expressions);
foreach($expressions as $expression)
{
$where[] = '(article LIKE ? OR Resume LIKE ?)';
$param[] = '%'.$expression.'%';
$param[] = '%'.$expression.'%';
}
//recherche dans la liste des articles à partir d'un mot clé
$req = 'SELECT Id, article, Resume, Disponibilte FROM list WHERE ' . implode($operateur, $where);
$sth = $bdd->prepare($req);
$sth->execute($param);
//Boucle pour afficher les résultats dans le tableau
while($dnn = $sth->fetch())
{
?>
<tr>
<td style="background-color:#DCDCDC;border:1px #C0C0C0 solid;text-align:left;vertical-align:top;height:12px"><span style="color:#000000;font-family:Arial;font-size:11px;"><div onClick="window.open('../description.php?Id=<?php echo $dnn['Id'] ?>','','width=600,height=200')"><?php if($surligner)//Si il faut surligner les mots, on les surligne
{
if($type==3)
{
echo substr((preg_replace('#('.preg_quote($rec).')#i', '<strong>$1</strong>', $dnn['article'])),0,70);//On surligne l'expression exacte
}
else
{
echo substr((preg_replace('#('.str_replace(' ','|',preg_quote($rec)).')#i', '<strong>$1</strong>', $dnn['article'])),0,70);//On surligne les mots cles de la recherche
}
}
else
{
echo substr(($dnn['article']),0,70);//On ne surligne pas
} ?></div></span></td>
<td rowspan=2 style="background-color:#DCDCDC;border:1px #C0C0C0 solid;text-align:left;vertical-align:top;height:12px"><span style="color:#000000;font-family:Arial;font-size:11px;"><?php if($surligner)//Si il faut surligner les mots, on les surligne
{
if($type==3)
{
echo substr((preg_replace('#('.preg_quote($rec).')#i', '<strong>$1</strong>', $dnn['Resume'])),0,70),'...';//On surligne l'expression exacte
}
else
{
echo substr((preg_replace('#('.str_replace(' ','|',preg_quote($rec)).')#i', '<strong>$1</strong>', $dnn['Resume'])),0,70),'...' ;//On surligne les mots cles de la recherche
}
}
else
{
echo substr(($dnn['Resume']),0,67),'...';//On ne surligne pas
}
?></span></td><td style="background-color:#DCDCDC;border:1px #C0C0C0 solid;text-align:center;vertical-align:top;height:12px"><span style="color:#000000;font-family:Arial;font-size:10px;"><?php echo $dnn['Disponibilite']; ?></span>
</td></tr>
</table> |