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
| < ?
/******************************************************************
* VARIABLES A MODIFIER
******************************************************************/
// NOMBRE DE RESULTATS PAR PAGE
$limit=2;
// NOM DE CE SCRIPT
$script_name="recherche.php3";
// RECHERCHE AVEC TOUS LES MOTS : METTEZ "and"
// RECHERCHER LES PAGES QUI CONTIENNENT AU MOINS UN MOT : METTEZ "or"
$et_ou="or";
/******************************************************************
* PROGRAMME PRINCIPAL
******************************************************************/
include('connexion.php');
$mot="";
$mot=strtolower($mot);
$mots=split(" ",$mot);
$nombre_mots=count($mots);
$z=1;
$texte="Pages contenant <b>"$mots[0]"</b>";
$phrase="'%$mots[0]%'";
while($z<$nombre_mots)
{
$phrase.=" ".$et_ou." mots like '%$mots[$z]%'";
$texte.=" ";
if($et_ou=="and"){$texte.="et";}else{$texte.="ou";}
$texte.=" <b>"$mots[$z]"</b>";
$z++;
}
$debut="0";
$page="1";
if($debut==""){$debut=0;}
$debut=$page*$limit;
// NOMBRE TOTAL D'ENREGISTREMENTS REPONDANT A LA REQUETE
$sql="SELECT count(*) FROM recherche WHERE mots LIKE $phrase ORDER BY id";
$requete=mysql_query($sql);
$nb_total=mysql_result($requete,0,"count(*)");
$sql1="SELECT * FROM recherche WHERE mots LIKE $phrase LIMIT $debut,$limit";
$requete1=mysql_query($sql1);
$num=mysql_num_rows($requete1);
echo"$num";
// DEFINITION DU MESSAGE A AFFICHER
if ($num==0) {echo "Désolé, aucune page de ce site ne contient <b>$mot</b>...";}
else if ($mot=="") {echo "Veuillez saisir un ou plusieurs mot-clés avant de cliquer sur 'OK' !";}
else if (strlen($mot)<2) {echo "Veuillez saisir au moins 2 caractères.";}
// AFFICHAGE DES RESULTATS
else {
echo "<b>$nb_total</b> réponse";
if ($nb_total>1) {echo "s";}
echo "<br>$texte";
$i=0;
while($i<$num)
{
$url=mysql_result($requete,$i,"url");
$description=mysql_result($requete,$i,"description");
$titre=mysql_result($requete,$i,"titre");
echo "<br><br><a href=\"$url\"><b>$titre</b></a><br>$description<br><font size=1>$url</font>\n";
$i++;
}
echo "<br><br>";
// AFFICHAGE DU LIEN PRECEDENT SI BESOIN EST
// (LA PREMIERE PAGES EST 0)
if ($page>0)
{
$precedent=$page-1;
print "<a href=\"$script_name?page=$precedent&mot=$mot\">PRECEDENT</a> \n";
}
// AFFICHAGE DES NUMEROS DE PAGE
$i=0;$j=1;
if($nb_total>$limit)
{
while($i<($nb_total/$limit))
{
if($i!=$page){echo "(<a href=\"$script_name?page=$i&mot=$mot\">$j</a>) ";}
else {echo "<b>($j)</b> ";}
$i++;$j++;
}
}
// AFFICHAGE DU LIEN SUIVANT SI BESOIN EST
if($debut+$limit<$nb_total)
{
$suivant=$page+1;
echo "<a href=\"$script_name?page=$suivant&mot=$mot\">SUIVANT</a>";
}
}
// DECONNEXION DE LA BASE DE DONNEE
mysql_close();
?> |
Partager