Index du Forum » » Le coin des codeurs

Auteur

DB qui me joue des tours
elpipo
87    

  Posté : 11-11-2003 20:31

ha

Of course ça marche mieux comme ça ...
Mais ma DB se trouve ou ? car je dois récupérer les données se trouvant dans le journal du membre (scusez pour ma nullité )
En effet le moteur de recherche doit pointer sur la DB, et surtout sur les données contenues dans $user_journal

J'ai ici placé le moteur de recherche dans le répertoire /sql ...

merci d'avance

Ps : j'ai joint le fichierdu moteur ...
[hide]
<?
//----------
// Fichier : recherche.php
// Auteur : Doudou
// Derniere modif : 10/11/2003
// Date creation : 11/07/2001
// Objet : recherche sur le site
//
//----------
// inclusion des variables programmes
require('admin/var.inc.php');

?>
<form method="post" action="recherche.php" name="recherche" target="1">
<div align=center>
<h2>Recherche sur Doudou.net</h2>
Une autre recherche ? <input name="recherche" style="BACKGROUND-COLOR: #DDEEFF; BORDER-BOTTOM: #990099 1px solid; BORDER-LEFT: #990099 1px solid; BORDER-RIGHT: #990099 1px solid; BORDER-TOP: #990099 1px solid; COLOR: #0000A0; FONT-FAMILY: Arial; FONT-SIZE: 8pt" size="15" maxlength="25" value="Rechercher" onfocus="if (this.value=='Rechercher') this.value=''">
<input style="BACKGROUND-COLOR: #CDCDCD; BORDER-BOTTOM: #990099 1px solid; BORDER-LEFT: #990099 1px solid; BORDER-RIGHT: #990099 1px solid; BORDER-TOP: #990099 1px solid; COLOR: #0000A0; FONT-FAMILY: Arial; FONT-SIZE: 8pt" type=submit value=ok name="submit">
</div>
</form>
<?
if (empty($recherche))
{
echo "<h1 align=center>Veuillez saisir un critère de recherche.</h1>";
}
else
{
// on met en minuscule
$recherche = strtolower($recherche);
// on remplace les espaces par des %
$recherche_req = ereg_replace(' ','%',$recherche);


$req = "SELECT * FROM $table_moteur WHERE user_journal LIKE '%$recherche_req%'";
$log = mysql_connect($serveur,$id,$mdp) or die('Connexion à la base $bd impossible');
//echo "connexion BD ok<br>";
//echo "requete : $req<br>";
$res = mysql_db_query($bd,$req,$log) or die('Recupération impossible');
$nb_rep = mysql_num_rows($res);
if ($nb_rep<1)
{
echo "<h1 align=center>Aucune page ne contient '$recherche'.</h1><h2 align=center>Veuillez modifier votre critère.</h2>";
}
else
{
echo "<div align=center><font size=+1>Le terme '<b>$recherche</b>' apparait dans $nb_rep page";
if ($nb_rep>1)
{
echo 's';
}
echo ".</font></div><br>";
while ($tab = mysql_fetch_array($res))
{
$extrait = "";
// on decoupe l'extrait de page a afficher
$position = strpos($tab['user_journal'],$recherche);


$pos_init = 0;
if ($position>30)
{
$pos_init = $position-30;
}
$taille_chaine = strlen($tab['user_journal']);
$pos_final = $taille_chaine;
$taille_recherche = strlen($recherche);
if ($taille_chaine > ($position+$taille_recherche+70))
$pos_final = $taille_recherche+100;
//echo "Position : $position - taille : $taille_chaine";
//echo " debut : $pos_init, fin : $pos_final<br>";
$extrait = substr($tab['user_journal'],$pos_init,$pos_final);
$extrait = ereg_replace($recherche,"<b>$recherche</b>",$extrait); echo "  * Page <a href='modules.php?ModPath=Jane-User&ModStart=jane-user&op=userinfo& uname=$tab[uname]
'>$tab[url]</a> => $tab[name]<br>
<i>...$extrait...</i><br><br& gt;";
}
}
}
?>
<form method="post" action="recherche.php" name="recherche" target="1">
<div align=center>
Une autre recherche ? <input name="recherche" style="BACKGROUND-COLOR: #DDEEFF; BORDER-BOTTOM: #990099 1px solid; BORDER-LEFT: #990099 1px solid; BORDER-RIGHT: #990099 1px solid; BORDER-TOP: #990099 1px solid; COLOR: #0000A0; FONT-FAMILY: Arial; FONT-SIZE: 8pt" size="15" maxlength="25" value="Rechercher" onfocus="if (this.value=='Rechercher') this.value=''">
<input style="BACKGROUND-COLOR: #CDCDCD; BORDER-BOTTOM: #990099 1px solid; BORDER-LEFT: #990099 1px solid; BORDER-RIGHT: #990099 1px solid; BORDER-TOP: #990099 1px solid; COLOR: #0000A0; FONT-FAMILY: Arial; FONT-SIZE: 8pt" type=submit value=ok name="submit">
</div>
</form>
[hide]
< BR>
[ Message édité par : elpipo : 11-11-2003 20:45 ]



Cet article provient de NPDS

http://www.npds.org/viewtopic.php?topic=8536&forum=5