Portail PHP

Forum de discussion et d'aide au php

Vous n'êtes pas identifié.

Annonce

Regles d'utilisation des forums : pensez à toujours les respecter si vous désirez obtenir des réponses rapides.
FAQ : pensez à toujours chercher dedans si la réponse à votre question est dedans.
Proposez vos news : si vous avez un evenement à annoncer
le chat : venez discuter de php.
 

#1 01-06-2005 13:26:52

snap
Membre
Date d'inscription: 25-05-2005
Messages: 78

Petit moteur de recherche

BONJOUR

Je souhaite realiser un moteur de recherche sur ma base de connée ; Voici mon scrpt;

Code:

<form method="post" action="rechercher.php">
 <table width="159" border="0" align="center" cellpadding="0" 

cellspacing="0">
   <tr> 
     <td width="67"> <div align="center"> 
         <input name="recherche" type="text" size="20">
       </div></td>
     <td width="30"></td>
     <td width="68"><input type="submit" name="recherche" 

value="recherche"> </td>
   </tr>
 </table>
 </form>

Rechercher.php

Code:

<html>
<body>
<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<TABLE width="100%" BORDER=0 cellpadding=0 cellspacing=0>
<tr> 
<TD ALIGN=top><span class="style5">Nom</span></td>
<td></td>
    <TD ALIGN=top><span class="style5">Prenom</span></td>
<td></td>
<TD ALIGN=top><span class="style5">code</span></td>
<td></td>
<TD ALIGN=top><span class="style5">ville</span></td>
<td></td>
<TD ALIGN=top><span class="style5">jour de dispo</span></td>
<td></td>
    <TD ALIGN=top><span class="style5">Moi de dispo</span></td>
<td></td>
    <TD ALIGN=top><span class="style5">Ann&eacute;e dispo</span></td>
<td></td>
    <TD ALIGN=top><span class="style5">cv</span></td> </TR>

<?

$db = mysql_connect('localhost', 'root', ''); 
mysql_select_db('formu',$db); 

$recherche = $_POST['recherche'];

//Recherche $recherche dans une table
$req ="SELECT nom, prenom,code,ville, dispo_jour,dispo_mois, dispo_annee
FROM form1
WHERE nom LIKE '%$recherche%' OR prenom LIKE '%$recherche%' OR code LIKE '%$recherche%' OR ville LIKE '%$recherche%' OR 

fonction LIKE '%$recherche%' OR niveau LIKE '%$recherche%' OR region1 LIKE '%$recherche%' ";

$Erreur = mysql_error();


//on ressort les infos par ordres alphabétiques
$res =mysql_query($req);
if($res === false) die(mysql_error());


while( $tablo = mysql_fetch_object($res))
{ 
echo "<tr>"; 
echo "<td nowrap class="style4">".$tablo->nom."</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">".$tablo->prenom."</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">".$tablo->code."</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">".$tablo->ville."</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">".$tablo->dispo_jour."</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">".$tablo->dispo_mois."</td>";
echo "<td></td>";
echo "<td nowrap class="style4">".$tablo->dispo_annee."</td>"; 
echo "<td></td>";
echo "<td nowrap class="style6"><a href="fichier/".$tablo->nomDestination."">Telecharger</a></td>"; 
echo "</tr>"; 

}
mysql_close(); 

?> 
</table>
</table>
</body>
</html>

Malheuresement comme resulta je n'est qu'un tableau vide alors que m'a base est pleinne.

J'ai fais un echo de ma requet puis je l'ai testé sur phpadmin et elle m' a donnée un resultat .

Je ne vois pas ou est mon erreur. roll
MERCI POUR VOTRE AIDE

Hors ligne

 

#2 01-06-2005 15:58:03

palmivore
Modérateur global
Lieu: 49 - Maine et Loire
Date d'inscription: 07-04-2005
Messages: 1783
Site web

Re: Petit moteur de recherche

as tu une erreur retournée par MySql ?

c'est normal que ta table s'apelle 'form1' ?

Hors ligne

 

#3 02-06-2005 08:16:52

snap
Membre
Date d'inscription: 25-05-2005
Messages: 78

Re: Petit moteur de recherche

Bonjour

J'ai fait un test de ma requet sur phpadmin et elle marche .

Mais bon j'ai remodifié un peu mon code .Mais cette fois si j'ai sa comme erreur;

Parse error: parse error in c:program fileseasyphp1-8wwwrechercher.php on line 130.

Recheche.php


Code:

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>

<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
 <TABLE width="100%" BORDER=0 cellpadding=0 cellspacing=0>
<tr> 
<TD ALIGN=top><span class="style5">Nom</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Prenom</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Code postale</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Ville</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Sexe</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Ann&eacute;e de naissance</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">&nbsp;Secteur d'activit&eacute;</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">&nbsp;Ann&eacute;e
d'exp&eacute;rience </span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Niveau d'&eacute;tudes</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">R&eacute;gions souhait&eacute;es</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Mobilit&eacute; g&eacute;ographique
      </span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Type <br>
      </span></td>
<td></td>
      <TD ALIGN=top><span class="style5">jour de diponibilit&eacute;</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Moi de diponibilit&eacute;</span></td>
<td></td>
      <TD ALIGN=top><span class="style5">Ann&eacute;e de diponibilit&eacute;</span></td>

<td></td>
      <TD ALIGN=top><span class="style5">cv</span></td> </TR>

<? 

$db = mysql_connect('localhost', 'root', ''); 

mysql_select_db('formu',$db); 


if(isset($_GET['recherche'])) 
{ 
  if($_GET['recherche']=='') 
  { 
    echo"<h2>Recherche</h2>"; 
    echo"Veuillez saisir un critère de recherche"; 
  } 
  elseif(strlen($_GET['recherche'])<3) 
  { 
    echo"<h2>Recherche</h2>"; 
    echo"Veuillez saisir un critère de recherche de plus de 3 caractères"; 
  } 
  else 
  { 
    $recherche=$_GET['recherche']; 
    echo "<title>Recherche de  : ".$recherche."</title> 
     </head><body> 

      <table align=center width=50%><tr><td><img src=images/panneaux003.gif><td><font size=4 color=white face=Comic Sans MS>Recherche de  : ".$rech."</font></table>"; 
   
//include("connexion.php"); 

    $rq = "SELECT * FROM form1 WHERE nom LIKE '%$recherche%' OR prenom LIKE '%$recherche%' OR code LIKE '%$recherche%' OR ville LIKE '%$recherche%' OR fonction LIKE '%$recherche%' OR niveau LIKE '%$recherche%' OR region1 LIKE '%$recherche%'"; 
echo " $rq ";


    $res=mysql_query($rq); 
    $cont=mysql_num_rows($res); 
    if($cont<=0) 
    { 
      echo"<br>Aucun résultat trouvé dans la base de donnée<br><br>"; 
    } 
    
      while ($tablo = mysql_fetch_object($res)) 
{ 
echo "<tr>"; 
echo "<td nowrap class="style4" >$tablo->nom</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->prenom</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->code</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">$tablo->ville</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">$tablo->sex</td>";
 echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->ddn_a</td>";
 echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->fonction</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->ann_exp</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->niveau</td>";
 echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->region1</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->mobil</td>";
 echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->type_mobil</td>";
 echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->dispo_jour</td>"; 
echo "<td></td>";
echo "<td nowrap class="style4">$tablo->dispo_mois</td>";
echo "<td></td>";
echo "<td nowrap class="style4" >$tablo->dispo_annee</td>";
 echo "<td></td>";
echo "<td nowrap class="style6" ><a href="cv/$tablo->nomDestination">Telecharger</a></td>"; 
echo "</tr>"; 
} 

?>
</table>
</table>
</body>
</html> // ici la ligne 130

Envoi.php

Code:


<?php

echo'<form method="GET" action="rechercher.php">
  <table width="159" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="67"> <div align="center"> 
          <input name="recherche" type="text" size="20">
        </div></td>
      <td width="30"></td>
      <td width="68"><input type="submit" value="cherche"> </td>
    </tr>
  </table>
  </form>';
  
  ?> 

MERCI POUR VOTRE AIDE

Hors ligne

 

#4 02-06-2005 08:25:52

palmivore
Modérateur global
Lieu: 49 - Maine et Loire
Date d'inscription: 07-04-2005
Messages: 1783
Site web

Re: Petit moteur de recherche

Dans rechercher.php, il te manque 2 }

Voici ce que tu dois mettre

Code:

        echo "</tr>"; //Ligne 122
        } 
    }
}
?> 
</table> 
</table> 
</body> 
</html> // ici la ligne 130 

Hors ligne

 

#5 02-06-2005 08:26:13

kazhar
Ex-Webmaster
Lieu: Orléans
Date d'inscription: 25-06-2004
Messages: 3381
Site web

Re: Petit moteur de recherche

au lieu de donner toute ta page, donne uniquement la ligne 130 ...
la premiere chose à faire lorsque tu a une erreur, est de voir la ligne, et de trouver pourquoi il mets cette erreur à cette ligne...
il doit te manquer des }

edit : encore une fois, pas assez rapide lol

Hors ligne

 

#6 02-06-2005 08:29:25

palmivore
Modérateur global
Lieu: 49 - Maine et Loire
Date d'inscription: 07-04-2005
Messages: 1783
Site web

Re: Petit moteur de recherche

autre chose, je te conseille de virer la ligne 78 sinon tes utilisateurs vont avoir ta requête en plein milieu de la page wink

Hors ligne

 

#7 02-06-2005 08:58:51

snap
Membre
Date d'inscription: 25-05-2005
Messages: 78

Re: Petit moteur de recherche

Bonjour
Merci c'est cooll sa marche , Merci beaucoup!!!!!!

J'ai juste un petit souci , j'ai un decallage entre les colonne du tableau et la recherche (ce que l'on a trouvé ) , pas mis au bon endroit, de plus ce que l'on trouve ne prend pas consideration le style associé.

Hors ligne

 

#8 02-06-2005 09:15:41

palmivore
Modérateur global
Lieu: 49 - Maine et Loire
Date d'inscription: 07-04-2005
Messages: 1783
Site web

Re: Petit moteur de recherche

On ne va pas tout faire à ta place non plus smile

Mettre les infos dans les celulles tu dois savoir le faire lol

Hors ligne

 

#9 02-06-2005 09:52:32

snap
Membre
Date d'inscription: 25-05-2005
Messages: 78

Re: Petit moteur de recherche

:oops:  ok!!
Je cherche , le comment du pourquoi?

Hors ligne

 

#10 02-06-2005 12:09:20

snap
Membre
Date d'inscription: 25-05-2005
Messages: 78

Re: Petit moteur de recherche

Re Bonjour

franchement , j'ai retourné mon srcipt dans tous les sens et je suis arrrivé a un resulta qui ma l'air correct ,mais j'ai cette erreur :oops:  ;

Code:

Parse error: parse error, expecting `','' or `';'' in c:program fileseasyphp1-8wwwrechercher.php on line 89

J'ai bien fermé les guillemé "" partout aprés chaque echo.......
Voici le code remanier;

Code:

<? 

$db = mysql_connect('localhost', 'root', ''); 

mysql_select_db('cv_tek',$db);  


if(isset($_GET['recherche'])) 
{ 
  if($_GET['recherche']=='') 
  { 
    echo"<h2>Recherche</h2>"; 
    echo"Veuillez saisir un critère de recherche"; 
  } 
  elseif(strlen($_GET['recherche'])<3) 
  { 
    echo"<h2>Recherche</h2>"; 
    echo"Veuillez saisir un critère de recherche de plus de 3 caractères"; 
  } 
  else 
  { 
    $recherche=$_GET['recherche']; 
    echo "<title>Recherche de  : ".$recherche."</title> 
     <body>
      <table align=center width=50%><tr><td>Recherche de  : ".$recherche."</font></table>"; 
   
//include("connexion.php"); 

    $rq = "SELECT * FROM cv WHERE nom LIKE '%$recherche%' OR prenom LIKE '%$recherche%' OR code LIKE '%$recherche%' OR ville LIKE '%$recherche%' OR fonction LIKE '%$recherche%' OR niveau LIKE '%$recherche%' OR region1 LIKE '%$recherche%'"; 
//echo " $rq ";


    $res=mysql_query($rq); 
    $cont=mysql_num_rows($res); 
    if($cont<=0) 
    { 
      echo"<br>Aucun résultat trouvé dans la base de donnée<br><br>"; 
    } 
    
else 
    { 
      echo "<br><table border='3' cellspacing='0' bordercolor=#D8EDFF width=100%><tr bgcolor='#2080c0'>; // ligne 89
      echo "<TD ALIGN=top><span class="style5">Nom</span></td>";

    echo "<TD ALIGN=top><span class="style5">Prenom</span></td>";

     echo "<TD ALIGN=top><span class="style5">Code postale</span></td>";

     echo "<TD ALIGN=top><span class="style5">Ville</span></td>";

     echo "<TD ALIGN=top><span class="style5">Sexe</span></td>";

      echo "<TD ALIGN=top><span class="style5">Ann&eacute;e de naissance</span></td>";

      echo "<TD ALIGN=top><span class="style5">&nbsp;Secteur d'activit&eacute;</span></td>";

   echo " <TD ALIGN=top><span class="style5">&nbsp;Ann&eacute;e d'exp&eacute;rience </span></td>";

     echo "<TD ALIGN=top><span class="style5">Niveau d'&eacute;tudes</span></td>";

      echo " <TD ALIGN=top><span class="style5">R&eacute;gions souhait&eacute;es</span></td>";

      echo "  <TD ALIGN=top><span class="style5">Mobilit&eacute; g&eacute;ographique </span></td>";

     echo " <TD ALIGN=top><span class="style5">Type <br></span></td>";

     echo " <TD ALIGN=top><span class="style5">jour de diponibilit&eacute;</span></td>";

      echo " <TD ALIGN=top><span class="style5">Moi de diponibilit&eacute;</span></td>";

   echo " <TD ALIGN=top><span class="style5">Ann&eacute;e de diponibilit&eacute;</span></td>";

 echo " <TD ALIGN=top><span class="style5">cv</span></td>"; 
      echo "</tr>"; 


      while ($tablo = mysql_fetch_object($res)) 
{ 
echo "<td nowrap class="style4" >$tablo->nom</td>"; 

echo "<td nowrap class="style4" >$tablo->prenom</td>"; 

echo "<td nowrap class="style4" >$tablo->code</td>"; 

echo "<td nowrap class="style4">$tablo->ville</td>"; 

echo "<td nowrap class="style4">$tablo->sex</td>";

echo "<td nowrap class="style4" >$tablo->ddn_a</td>";

echo "<td nowrap class="style4" >$tablo->fonction</td>"; 

echo "<td nowrap class="style4" >$tablo->ann_exp</td>"; 

echo "<td nowrap class="style4" >$tablo->niveau</td>";

echo "<td nowrap class="style4" >$tablo->region1</td>"; 

echo "<td nowrap class="style4" >$tablo->mobil</td>";

echo "<td nowrap class="style4" >$tablo->type_mobil</td>";

echo "<td nowrap class="style4" >$tablo->dispo_jour</td>"; 

echo "<td nowrap class="style4">$tablo->dispo_mois</td>";

echo "<td nowrap class="style4" >$tablo->dispo_annee</td>";

echo "<td nowrap class="style6" ><a href="cv/$tablo->nomDestination">Telecharger</a></td>"; 

}
echo "</table><br>"; 
}
}
}

?>
</table>
</table>
</body>
</html>

Merci

Hors ligne

 

#11 02-06-2005 12:14:04

kazhar
Ex-Webmaster
Lieu: Orléans
Date d'inscription: 25-06-2004
Messages: 3381
Site web

Re: Petit moteur de recherche

et encore une fois, ne donne que la ligne 89... inutile de faire un c/c de toute ta page...
apparemment, tu mets un , à la place d'un ; en fin de ligne...

Hors ligne

 

#12 02-06-2005 12:40:44

snap
Membre
Date d'inscription: 25-05-2005
Messages: 78

Re: Petit moteur de recherche

LIGNE 89 :

Code:

echo "<br><table border='3' cellspacing='0' bordercolor=#D8EDFF width=100%><tr bgcolor='#2080c0'>";

sa ma l'air correct  ......enfin je pense . j'ai relancé le programme et j'ai toujours la meme erreur.

Hors ligne

 

#13 02-06-2005 12:42:34

kazhar
Ex-Webmaster
Lieu: Orléans
Date d'inscription: 25-06-2004
Messages: 3381
Site web

Re: Petit moteur de recherche

tu ferme pas ton "
de la est ton erreur jeune padawan

Hors ligne

 

#14 02-06-2005 12:57:50

snap
Membre
Date d'inscription: 25-05-2005
Messages: 78

Re: Petit moteur de recherche

Toujours la meme erreur ,méme aprés modification
J'ai mis sa ;

Code:

echo "<br><table border='3' cellspacing='0' bordercolor=#D8EDFF width=100%><tr bgcolor='#2080c0'>";

Jeune jeda , je n'y arrive pas .
Tatatataaaaaata titatataaaaaaaaata ttalalalaaaa

Hors ligne

 

#15 02-06-2005 13:01:46

kazhar
Ex-Webmaster
Lieu: Orléans
Date d'inscription: 25-06-2004
Messages: 3381
Site web

Re: Petit moteur de recherche

Code:

echo "<TD ALIGN=top><span class="style5">Nom</span></td>";

dans toutes tes lignes d'apres... ton class, tu mets des " alors qu'ils sont deja ouverts pour le echo.
remplace tes lignes :

Code:

echo "<TD ALIGN=top><span class="style5">Nom</span></td>";

Hors ligne