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
| <?php //requete pour la liste des articles sauvegardée
$reponse = $session->query("SELECT article FROM list WHERE id_session = '$mon_id' ");
while ($donnees = $reponse->fetch())
{
$rec = htmlspecialchars($donnees['article']);
//On dertermine les identifiants, les noms et les informations des articles et on recherche
$req = 'SELECT Id, article, Resume, FROM boutique WHERE ';
if($type==1)
{//ayant un des mots dans leurs informations
$mots = explode(' ',$rec);//On separe lexpression en mots cles
$result = 0;
foreach($mots as $mot)
{
$req .= ' article LIKE "%'.$mot.'%" OR Resume LIKE "%'.$mot.'%" OR ';
//$req .= 'ORDER by article ASC ';
$nb = $bdd->prepare('SELECT COUNT(*) FROM boutique WHERE article LIKE :mot OR Resume LIKE :mot ');
$nb->execute(array( ':mot' => "%$mot%" ));
}
$req .= ' 1=0';
$convert = $convert + (int)$nb ->fetchColumn();
}
elseif($type==2)
{//ayant tous les mots dans leurs informations
$mots = explode(' ',$rec);//En separe lexpression en mots cles
foreach($mots as $mot)
{
$req .= ' article LIKE "%'.$mot.'%" OR Resume LIKE "%'.$mot.'%" AND ';
$nb = $bdd->prepare('SELECT COUNT(*) FROM boutique WHERE article LIKE :mot OR Resume LIKE :mot ');
$nb->execute(array( ':mot' => "%$mot%" ));
}
$req .= ' 1=1';
$convert = $convert + (int)$nb ->fetchColumn();
}
else
{//ayant l'expression exacte dans leurs informations
$req .= ' article LIKE "%'.$rec.'%" OR Resume LIKE "%'.$rec.'%"';
$nb = $bdd->prepare('SELECT COUNT(*) FROM boutique WHERE article LIKE :rec OR Resume LIKE :rec ');
$nb->execute(array( ':rec' => "%$rec%" ));
}
$convert = $convert + (int)$nb ->fetchColumn();
$requete = $bdd->query($req);
//On affiche les resultats
while($dnn = $requete->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['Emission'])),0,70);//On surligne les mots cles de la recherche
}
}
else
{
echo substr(($dnn['Emission']),0,70);//On ne surligne pas
} ?></span>
</td></tr>
</table>
<?php
}
}
?> |
Partager