par
sylvaing26 » 25 avr. 2007, 20:09
Mon code est fini et fonctionnel
je le poste si ca peut aider quelqun ...
<?php
/// Affichage du nombre de résultats
include ("inc/connect.php");
MYSQL_CONNECT($serveur,$utilisateur,$mdp) or die ("Connexion impossible");
MYSQL_SELECT_DB($db) or die ("Connexion à la base $base impossible");
if (!empty($recherche)){
$recherche=strtolower($recherche); //on passe en minuscule
$mots = str_replace("+", " ", trim($recherche)); //on remplace les + par des espaces
$mots = str_replace("\"", " ", $mots); //idem pour \
$mots = str_replace(" de ", " ", $mots); //idem pour de
$mots = str_replace(" et ", " ", $mots);
$mots = str_replace(" sur ", " ", $mots);
$mots = str_replace(" la ", " ", $mots);
$mots = str_replace(" le ", " ", $mots);
$mots = str_replace(" avec ", " ", $mots);
$mots = str_replace(", ", " ", $mots); //idem pour ,
$mots = str_replace(",", " ", $mots); //idem pour ,
$mots = str_replace(":", "", $mots); //idem pour :
$recherche=rawurlencode($recherche); //on encode la recherche
$tabe=explode(" " , $mots);
$nbe=count($tabe);
$sql1="SELECT * FROM recherche WHERE mots LIKE '%$tabe[0]%'"; //on prépare la requête SQL.
for($i=1 ; $i<$nbe; $i++)
{
$sql1.="AND mots LIKE \"%$tabe[$i]%\""; // on boucle pour integrer tous les mots dans la requête
}
$resulta = mysql_db_query($db,$sql1);// on execute la requête SQL.
$total = mysql_num_rows($resulta);
if ($total == 0)
{
echo "<p align=center>Aucun résultat !</p></span></font>";
}
elseif ($total == 1)
{
echo "<p style='margin-top:0; margin-right:400; margin-bottom:5; margin-left:30; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='center'><span style='font-size:7pt;'><font face='Verdana'>";
echo "<b>$total</b> résultat</p></span></font>";
}
elseif ($total > 1)
{
echo "<p style='margin-top:0; margin-right:400; margin-bottom:5; margin-left:30; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='center'><span style='font-size:7pt;'><font face='Verdana'>";
echo "<b>$total</b> résultats</p></span></font>";
}
}
mysql_free_result($resulta);
mysql_close();
?>
///////////Affichage des images
<?php
$limit=12;
MYSQL_CONNECT($serveur,$utilisateur,$mdp) or die ("Connexion impossible");
MYSQL_SELECT_DB($db) or die ("Connexion à la base $base impossible");
if (!isset($debut)) $debut = 0;
if (!empty($recherche))
{
$tab=explode(" " , $mots);
$nb=count($tab);
$sql="select * from recherche where mots like \"%$tab[0]%\" ";
for($i=1 ; $i<$nb; $i++)
{
$sql.="AND mots like \"%$tab[$i]%\" ";
}
$sql2=$sql; //requete permettant de connaitre le nombre de résultats
$sql.=" Limit $debut,$limit "; // requête limitante.
$result2 = mysql_db_query($db,$sql2);
$result = mysql_db_query($db,$sql);
echo "<p align=center style='margin-top:0;margin-bottom:0;'>";
if($result)
{
$nrows = mysql_num_rows($result2);
$flag = 1;
if(mysql_num_rows($result)==0) echo "";
else
{
while($row = mysql_fetch_array($result))
{
echo "<a href='voir.php?img=".$row["id"]."'";
echo ">";
echo "<img src='";
echo $row["rubrique"];
echo $row["dossier"];
echo "vignettes/" ;
echo $row["nom"];
echo "' align='absmiddle' border='0' vspace='5' hspace='5' alt=\"".$row["titre"]."\">";
echo "</a>";
}
/****************** Mise en place de la navigation. ************************************/
echo "<p style='margin-top:5; margin-right:30; margin-bottom:5; margin-left:30; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='right'><span style='font-size:8pt;'><font face='Verdana'>";
echo "Page : ";
$nombre=ceil($nrows/$limit);
for($i=1; $i<=$nombre; $i++)
{
echo "<a href=rechercher.php?rche=yes&recherche=$recherche&debut=".(($i-1)*$limit).">".$i."</a> ";
if($i < $nombre) {echo " - ";
}
}
}
}
}
else
{
echo("<p align=center style='margin-bottom:10;'><span style='font-size:10pt;'><font face='Verdana'>Entrez au moins un mot !</span></font></p>");
}
mysql_free_result($result);
mysql_close();
?>
<?php
//// Lien pour effectuer une nouvelle recherche
echo "</p><p style='margin-top:0; margin-right:30; margin-bottom:0; margin-left:340; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='center'>";
echo "<a href='rechercher.php'><span style='font-size:8pt;'><font face='Verdana'>";
echo "Nouvelle recherche";
echo "</font>";
echo "</span>";
echo "</a></p>";
?>
Bonne chance pour l'adapter ...
J'ai mis deux jours pour pondre ca ... mdr

Je suis novice ... faut le reconnaitre d'ailleurs il doit y avoir des erreurs dedans !
Mais ca marche et c'est le principal
Mon code est fini et fonctionnel
je le poste si ca peut aider quelqun ...
[php]<?php
/// Affichage du nombre de résultats
include ("inc/connect.php");
MYSQL_CONNECT($serveur,$utilisateur,$mdp) or die ("Connexion impossible");
MYSQL_SELECT_DB($db) or die ("Connexion à la base $base impossible");
if (!empty($recherche)){
$recherche=strtolower($recherche); //on passe en minuscule
$mots = str_replace("+", " ", trim($recherche)); //on remplace les + par des espaces
$mots = str_replace("\"", " ", $mots); //idem pour \
$mots = str_replace(" de ", " ", $mots); //idem pour de
$mots = str_replace(" et ", " ", $mots);
$mots = str_replace(" sur ", " ", $mots);
$mots = str_replace(" la ", " ", $mots);
$mots = str_replace(" le ", " ", $mots);
$mots = str_replace(" avec ", " ", $mots);
$mots = str_replace(", ", " ", $mots); //idem pour ,
$mots = str_replace(",", " ", $mots); //idem pour ,
$mots = str_replace(":", "", $mots); //idem pour :
$recherche=rawurlencode($recherche); //on encode la recherche
$tabe=explode(" " , $mots);
$nbe=count($tabe);
$sql1="SELECT * FROM recherche WHERE mots LIKE '%$tabe[0]%'"; //on prépare la requête SQL.
for($i=1 ; $i<$nbe; $i++)
{
$sql1.="AND mots LIKE \"%$tabe[$i]%\""; // on boucle pour integrer tous les mots dans la requête
}
$resulta = mysql_db_query($db,$sql1);// on execute la requête SQL.
$total = mysql_num_rows($resulta);
if ($total == 0)
{
echo "<p align=center>Aucun résultat !</p></span></font>";
}
elseif ($total == 1)
{
echo "<p style='margin-top:0; margin-right:400; margin-bottom:5; margin-left:30; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='center'><span style='font-size:7pt;'><font face='Verdana'>";
echo "<b>$total</b> résultat</p></span></font>";
}
elseif ($total > 1)
{
echo "<p style='margin-top:0; margin-right:400; margin-bottom:5; margin-left:30; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='center'><span style='font-size:7pt;'><font face='Verdana'>";
echo "<b>$total</b> résultats</p></span></font>";
}
}
mysql_free_result($resulta);
mysql_close();
?>
///////////Affichage des images
<?php
$limit=12;
MYSQL_CONNECT($serveur,$utilisateur,$mdp) or die ("Connexion impossible");
MYSQL_SELECT_DB($db) or die ("Connexion à la base $base impossible");
if (!isset($debut)) $debut = 0;
if (!empty($recherche))
{
$tab=explode(" " , $mots);
$nb=count($tab);
$sql="select * from recherche where mots like \"%$tab[0]%\" ";
for($i=1 ; $i<$nb; $i++)
{
$sql.="AND mots like \"%$tab[$i]%\" ";
}
$sql2=$sql; //requete permettant de connaitre le nombre de résultats
$sql.=" Limit $debut,$limit "; // requête limitante.
$result2 = mysql_db_query($db,$sql2);
$result = mysql_db_query($db,$sql);
echo "<p align=center style='margin-top:0;margin-bottom:0;'>";
if($result)
{
$nrows = mysql_num_rows($result2);
$flag = 1;
if(mysql_num_rows($result)==0) echo "";
else
{
while($row = mysql_fetch_array($result))
{
echo "<a href='voir.php?img=".$row["id"]."'";
echo ">";
echo "<img src='";
echo $row["rubrique"];
echo $row["dossier"];
echo "vignettes/" ;
echo $row["nom"];
echo "' align='absmiddle' border='0' vspace='5' hspace='5' alt=\"".$row["titre"]."\">";
echo "</a>";
}
/****************** Mise en place de la navigation. ************************************/
echo "<p style='margin-top:5; margin-right:30; margin-bottom:5; margin-left:30; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='right'><span style='font-size:8pt;'><font face='Verdana'>";
echo "Page : ";
$nombre=ceil($nrows/$limit);
for($i=1; $i<=$nombre; $i++)
{
echo "<a href=rechercher.php?rche=yes&recherche=$recherche&debut=".(($i-1)*$limit).">".$i."</a> ";
if($i < $nombre) {echo " - ";
}
}
}
}
}
else
{
echo("<p align=center style='margin-bottom:10;'><span style='font-size:10pt;'><font face='Verdana'>Entrez au moins un mot !</span></font></p>");
}
mysql_free_result($result);
mysql_close();
?>
<?php
//// Lien pour effectuer une nouvelle recherche
echo "</p><p style='margin-top:0; margin-right:30; margin-bottom:0; margin-left:340; padding:1px; border-top-width:1px; border-bottom-width:1px; border-bottom-color:rgb(87,113,39); border-top-style:dotted; border-bottom-style:dotted; border-tp-color:rgb(87,113,39);' align='center'>";
echo "<a href='rechercher.php'><span style='font-size:8pt;'><font face='Verdana'>";
echo "Nouvelle recherche";
echo "</font>";
echo "</span>";
echo "</a></p>";
?>
[/php]
Bonne chance pour l'adapter ...
J'ai mis deux jours pour pondre ca ... mdr :lol: Je suis novice ... faut le reconnaitre d'ailleurs il doit y avoir des erreurs dedans !
Mais ca marche et c'est le principal