Bonsoir,

je souhaite mettre sur mon site un moteur de recherche, au niveau de la recherche en elle même pas de soucis, c'est au niveau de la pagination que je m'en sors pas, cela ne fonctionne pas.
je pense que mon soucis se trouve au niveau del a variable page.

voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
<?php
/****************************************************************** 
*    VARIABLES A MODIFIER 
******************************************************************/
// NOMBRE DE RESULTATS PAR PAGE 
$limit=2;
// NOM DE CE SCRIPT 
$script_name="moteur.php";
// SERVEUR SQL 
$sql_serveur="localhost";
// LOGIN SQL 
$sql_user="root";
// MOT DE PASSE SQL 
$sql_passwd="XXXXXX";
// BASE DE DONNEE 
$database="deploiement";
// RECHERCHE AVEC TOUS LES titre : METTEZ "and" 
// RECHERCHER LES PAGES QUI CONTIENNENT AU MOINS UN MOT : METTEZ "or" 
$et_ou="or";
mysql_connect('localhost','root',XXXXXXXX);
mysql_select_db('deploiement'); // on se connecte à MySQL. Je vous laisse remplacer les différentes informations pour adapter à votre site.
 
/****************************************************************** 
*    PROGRAMME PRINCIPAL 
******************************************************************/
$mot = htmlspecialchars($_POST['mot']); 
$titre=split(" ",$mot);
$nombre_titre=count($titre);
 
$z=1;
$texte="Pages contenant <b>&quot;$titre[0]&quot;</b>";
$phrase="%$titre[0]%";
 
while($z<$nombre_titre)
    {
    $phrase.=" '.$et_ou.' titre like '%$titre[$z]%'";
    $texte.=" ";
    if($et_ou=="and" ){$texte.="et";}else{$texte.="ou";}
    $texte.=" <b>&quot;$titre[$z]&quot;</b>";
    $z++;
    }
 
if($debut=="" ){$debut=0;}
$page =0;
$debut=$page*$limit;
 
// NOMBRE TOTAL D'ENREGISTREMENTS REPONDANT A LA REQUETE 
 
$query = mysql_query("SELECT count(*) FROM contenu WHERE titre LIKE '%$phrase%' ORDER BY content_id DESC") or die (mysql_error()); $nb_total=mysql_result($query,0,"count(*)" );
 
$query = mysql_query("SELECT * FROM contenu WHERE titre LIKE '%$phrase%' ORDER BY content_id DESC limit $debut,$limit") or die (mysql_error()); 
$num = mysql_num_rows($query);
 
// DEFINITION DU MESSAGE A AFFICHER  ///////////////////////// a revoir ici ////////////////////////////
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&eacute;ponse";
if ($nb_total>1) {echo "s";}
echo "<br>$texte";
 
$i=0;
while($i<$num)
    {
    //$url=mysql_result($query,$i,"url" );
    $description=mysql_result($query,$i,"description" );
    $titre=mysql_result($query,$i,"titre" );
    //echo "<br><br><a href=\"$url\"><b>$titre</b></a><br>$description<br><font size=1>$url</font>\n";
	echo "<br><br><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>&nbsp;\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> )&nbsp;";}
        else {echo "<b>($j)</b>&nbsp;";}
        $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($db_link);
 
?>