Bonjour,
j'ai un petit soucis, j'ai voulu mettre un moteur de recherche sur mon site afin de pouvoir récupérer des informations de ma base de données. J'ai un tableau avec plusieurs colonnes et je voudrais pourvoir filtrer certaines lignes avec une "checkbox" + recherche par mots clés sur 2 colonnes. Pour l'instant je n'ai installé qu'une recherche sur une colonne (colonne 'description'), mais j'aimerais également faire une recherche croisée avec une colonnes supplémentaire ('nom').
Autre soucis, certains mots présents dans ma colonne 'description' ne ressortent pas, ou parfois il y a des erreurs. Exemple quand je recherche le mot "urologie" il me ressort des ligne avec "neurologie"...
merci beaucoup par avance pour votre aide.
voici ma page rechercher.php :
<?php
if (isset($_POST))
{
$recherche = htmlspecialchars($_POST['recherche']);
$and_ou_or = 'OR';
$mots = explode(" ", $recherche);
$nombre_mots = count ($mots);
$valeur_requete = '';
for($nombre_mots_boucle = 0; $nombre_mots_boucle < $nombre_mots; $nombre_mots_boucle++)
{
$valeur_requete .= '' . $and_ou_or . ' description LIKE \'%' . $mots[$nombre_mots_boucle] . '%\'';
}
$valeur_requete = ltrim($valeur_requete,$and_ou_or);
If (isset($_POST['Question1'])){
$q1=$_POST['Question1'];
$q1checked='checked';
}
else
{
$q1='0';
$q1checked='';
}
If (isset($_POST['Question2'])){
$q2=$_POST['Question2'];
$q2checked='checked';
}
else
{
$q2='0';
$q2checked='';
}
If (isset($_POST['Question3'])){
$q3=$_POST['Question3'];
$q3checked='checked';
}
else
{
$q3='0';
$q3checked='';
}
$requete2="type_id='$q1' OR type_id='$q2' OR type_id='$q3'";
session_start ();
$_SESSION['mots']=$valeur_requete;
$_SESSION['mots2']=$requete2;
$_SESSION['q1']=$q1checked;
$_SESSION['q2']=$q2checked;
$_SESSION['q3']=$q3checked;
echo '<meta http-equiv="refresh" content="0;URL=Index_thesaurus.php">';
}
?>
et la page depuis laquelle j'envoie vers 'rechercher.php' :
<?php
include ('log.php');
session_start ();
$requete=$_SESSION['mots'];
If (isset($_SESSION['mots']))
{
$requete=$_SESSION['mots'];
}
else
{
$requete="description LIKE '%%'";
}
If (isset($_SESSION['mots2']))
{
$requete2=$_SESSION['mots2'];
}
else
{
$requete2="type_id=1 OR type_id=2 OR type_id=3";
}
$q1checked=$_SESSION['q1'];
$q2checked=$_SESSION['q2'];
$q3checked=$_SESSION['q3'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>AAP</title>
<link rel="shortcut icon" href="http://www.dirc-est.fr/images/favicon.ico"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="http://www.dirc-est.fr/templates/simplicity_dotted/css/template_css.css" type="text/css" rel="stylesheet"/>
<link href="http://www.dirc-est.fr/templates/simplicity_dotted/css/acajou.css" type="text/css" rel="stylesheet"/>
<link href="http://www.dirc-est.fr/templates/simplicity_dotted/neojoomla.ico" rel="shortcut icon"/>
<script src="sorttable.js"></script>
<script type="text/javascript">
function valider(){
// si la valeur du champ prenom est non vide
if(document.form_recherche.Question1.checked==false && document.form_recherche.Question2.checked==false && document.form_recherche.Question3.checked==false) {
// sinon on affiche un message
alert("Merci de préciser au moins 1 type d'appels à projets dans vos critères de recherche");
// et on indique de ne pas envoyer le formulaire
return false;
}
};
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30413345-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body bgcolor="#ffffff">
<table style=margin-top:"40px;" align=center border=1 bordercolor="#FFFFFF" cellpadding="6" cellspacing="2" width="90%">
<tbody>
<tr>
<td width="75%">
<div>
<p> </p>
<p align="left"><a href="mailto:[email protected]"><img src="http://www.dirc-est.fr/AAP/boutoncontact.png" alt="Image" onmouseover="javascript:this.src='http://www.dirc-est.fr/AAP/boutoncontact2.png';" onmouseout="javascript:this.src='http://www.dirc-est.fr/AAP/boutoncontact.png';" /></a></font></p>
<p> </p>
<p id="info_date"></p>
</div>
</td>
<td width="75%">
<div>
<p> </p>
<p align="left"><font color="#800000" size="6" face="Tahoma"><img src="http://www.dirc-est.fr/AAP/logoThesaurus.png" alt="Thesaurus AAP" width="600" height="129" border="0"></font></p>
<p> </p>
<p id="info_date"></p>
</div>
</td>
</tr>
</tbody>
</table>
<table align=center border=1 bordercolor="#FFFFFF" cellpadding="6" cellspacing="2" width="91%" bgcolor="#FFFFFF">
<tr>
<td width="100%"><div align="justify">
<form name="form_recherche" method="post" action="rechercher.php" onsubmit="return valider();">
<div> <font style="font-size:12pt" face="TAHOMA" color="#800000"><b>
Votre Recherche :
<input type="text" name="recherche" /
<br />
<input type="submit" value="Rechercher" name="rechercher" />
</b></font>
<h2><font style="font-size:12pt" face="TAHOMA" color="#800000"><b>Type d'Appels à Projets</b></font></h2>
<INPUT TYPE="checkbox" NAME="Question1" VALUE="1" ID=Checkbox1 <?php echo"$q1checked";?>><font style="font-size:10pt" face="TAHOMA" color="#000000">Subventions de recherche</font><br>
<INPUT TYPE="checkbox" NAME="Question2" VALUE="2" ID=Checkbox2 <?php echo"$q2checked";?>><font style="font-size:10pt" face="TAHOMA" color="#000000">Bourses Jeunes Chercheurs</font><br>
<INPUT TYPE="checkbox" NAME="Question3" VALUE="3" ID=Checkbox3 <?php echo"$q3checked";?>><font style="font-size:10pt" face="TAHOMA" color="#000000">Prix récompensant un travail terminé</font><br>
</div>
</br>
<div align="left"> <font style="font-size:8pt" face="TAHOMA" color="#000000"><em> (vous pouvez cliquer sur les entêtes du tableau pour effectuer un tri) </em></font></div>
</form>
</div></td>
<td width="100%"><div align="right">
<h2><font style="font-size:12pt" face="TAHOMA" color="#000000"><b>les projets "cancer" sont recensés sur le site du cancéropôle </b></font></h2>
<div align="right"> <font style="font-size:8pt" face="TAHOMA" color="#000000"><em> (vous pouvez cliquer sur le lien ci-dessous pour les AAP en cancérologie) </em></font></div>
</br>
<a href="http://www.canceropole-ge.org/perl/dbcge/aap/Home" target="_blank"><img src="http://www.dirc-est.fr/images/logo-canceropole_grand_est.jpg" alt="AAP cancer" width="200" height="59" border="0" /></a></div></td>
<td width="131"> </td>
</tr>
</table>
<table style="margin-top:30px;" align=center border=1 bordercolor="#FFFFFF" cellpadding="6" cellspacing="2" class="sortable" width="92%">
<tr bgcolor="#cc6162" align="center">
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Spécialité</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Intitulé</b></font>
</td>
<td width="700" align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Description</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Organisme Emetteur</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Type</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Date Limite</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Montant (€)</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Lien</b></font>
</td>
</tr>
<?php
$sql = "SELECT * FROM aap INNER JOIN organisme ON organisme_id=id_organisme INNER JOIN type_aap ON id_type=type_id INNER JOIN specialite ON id_specialite=specialite_id WHERE ($requete) AND ($requete2) ORDER BY date_fin ASC";
$req = mysql_query($sql);
while($data=mysql_fetch_array($req)){
$array_date_mysql=explode("-",$data['date_fin']);
if( empty($array_date_mysql[0]) && empty($array_date_mysql[1]) && empty($array_date_mysql[2]) ){
$date_fr = 'projet permanent';
$nomTab = 'tabWithDateNull';
}
else{
$date_fr=$array_date_mysql[2]."/".$array_date_mysql[1]."/".$array_date_mysql[0];
$nomTab = 'tabWithDateNotNull';
}
${$nomTab}[] = '
<tr align="center">
<td>
<font style="font-size:10pt" face="TAHOMA" color="#321000"><b>
'.$data['nom'].'
</b></font>
</td>
<td>
<font style="font-size:8pt" face="TAHOMA" color="#505050"><b>
'.$data['nom_aap'].'
</b></font>
</td>
<td>
<P align="justify">
<font style="font-size:8pt" face="TAHOMA" color="#505050">
'.nl2br($data['description']).'
</font>
</td>
<td>
<font style="font-size:8pt" face="TAHOMA" color="#505050"><b>
'.$data['nom_organisme'].'
</b></font>
</td>
<td>
<font style="font-size:6pt" face="TAHOMA" color="#505050"><b>
'.$data['nom_type'].'
</b></font>
</td>
<td>
<font style="font-size:6pt" face="TAHOMA" color="#505050"><b>
'.$date_fr.'
</b></font>
</td>
<td>
<font style="font-size:6pt" face="TAHOMA" color="#505050"><b>
'.nl2br ($data['montant']).'
</b></font>
</td>
<td>
<font style="font-size:8pt" face="TAHOMA" color="#505050"><b>
<a href="'.$data['lien_internet'].'" target="_blank" ><img src="http://www.dirc-est.fr/images/clic_test6.png " border="0" width="38" height="38" alt="lien"></a>
</b></font>
</td>
</tr>';
}
$tabAll = array_merge($tabWithDateNotNull, $tabWithDateNull);
foreach($tabAll as $elt){
echo($elt);
}
?>
</table>
</body>
<br/>
<div align="center"><font style="font-size:10pt" face="TAHOMA" color="#800000"><b>Mis à Jour le 29/03/2012</b></font></div>
<br/>
</html>
Bonjour,
j'ai un petit soucis, j'ai voulu mettre un moteur de recherche sur mon site afin de pouvoir récupérer des informations de ma base de données. J'ai un tableau avec plusieurs colonnes et je voudrais pourvoir filtrer certaines lignes avec une "checkbox" + recherche par mots clés sur 2 colonnes. Pour l'instant je n'ai installé qu'une recherche sur une colonne (colonne 'description'), mais j'aimerais également faire une recherche croisée avec une colonnes supplémentaire ('nom').
Autre soucis, certains mots présents dans ma colonne 'description' ne ressortent pas, ou parfois il y a des erreurs. Exemple quand je recherche le mot "urologie" il me ressort des ligne avec "neurologie"...
merci beaucoup par avance pour votre aide.
voici ma page rechercher.php :
[php]
<?php
if (isset($_POST))
{
$recherche = htmlspecialchars($_POST['recherche']);
$and_ou_or = 'OR';
$mots = explode(" ", $recherche);
$nombre_mots = count ($mots);
$valeur_requete = '';
for($nombre_mots_boucle = 0; $nombre_mots_boucle < $nombre_mots; $nombre_mots_boucle++)
{
$valeur_requete .= '' . $and_ou_or . ' description LIKE \'%' . $mots[$nombre_mots_boucle] . '%\'';
}
$valeur_requete = ltrim($valeur_requete,$and_ou_or);
If (isset($_POST['Question1'])){
$q1=$_POST['Question1'];
$q1checked='checked';
}
else
{
$q1='0';
$q1checked='';
}
If (isset($_POST['Question2'])){
$q2=$_POST['Question2'];
$q2checked='checked';
}
else
{
$q2='0';
$q2checked='';
}
If (isset($_POST['Question3'])){
$q3=$_POST['Question3'];
$q3checked='checked';
}
else
{
$q3='0';
$q3checked='';
}
$requete2="type_id='$q1' OR type_id='$q2' OR type_id='$q3'";
session_start ();
$_SESSION['mots']=$valeur_requete;
$_SESSION['mots2']=$requete2;
$_SESSION['q1']=$q1checked;
$_SESSION['q2']=$q2checked;
$_SESSION['q3']=$q3checked;
echo '<meta http-equiv="refresh" content="0;URL=Index_thesaurus.php">';
}
?>
[/php]
et la page depuis laquelle j'envoie vers 'rechercher.php' :
[php]
<?php
include ('log.php');
session_start ();
$requete=$_SESSION['mots'];
If (isset($_SESSION['mots']))
{
$requete=$_SESSION['mots'];
}
else
{
$requete="description LIKE '%%'";
}
If (isset($_SESSION['mots2']))
{
$requete2=$_SESSION['mots2'];
}
else
{
$requete2="type_id=1 OR type_id=2 OR type_id=3";
}
$q1checked=$_SESSION['q1'];
$q2checked=$_SESSION['q2'];
$q3checked=$_SESSION['q3'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>AAP</title>
<link rel="shortcut icon" href="http://www.dirc-est.fr/images/favicon.ico"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="http://www.dirc-est.fr/templates/simplicity_dotted/css/template_css.css" type="text/css" rel="stylesheet"/>
<link href="http://www.dirc-est.fr/templates/simplicity_dotted/css/acajou.css" type="text/css" rel="stylesheet"/>
<link href="http://www.dirc-est.fr/templates/simplicity_dotted/neojoomla.ico" rel="shortcut icon"/>
<script src="sorttable.js"></script>
<script type="text/javascript">
function valider(){
// si la valeur du champ prenom est non vide
if(document.form_recherche.Question1.checked==false && document.form_recherche.Question2.checked==false && document.form_recherche.Question3.checked==false) {
// sinon on affiche un message
alert("Merci de préciser au moins 1 type d'appels à projets dans vos critères de recherche");
// et on indique de ne pas envoyer le formulaire
return false;
}
};
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30413345-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body bgcolor="#ffffff">
<table style=margin-top:"40px;" align=center border=1 bordercolor="#FFFFFF" cellpadding="6" cellspacing="2" width="90%">
<tbody>
<tr>
<td width="75%">
<div>
<p> </p>
<p align="left"><a href="mailto:
[email protected]"><img src="http://www.dirc-est.fr/AAP/boutoncontact.png" alt="Image" onmouseover="javascript:this.src='http://www.dirc-est.fr/AAP/boutoncontact2.png';" onmouseout="javascript:this.src='http://www.dirc-est.fr/AAP/boutoncontact.png';" /></a></font></p>
<p> </p>
<p id="info_date"></p>
</div>
</td>
<td width="75%">
<div>
<p> </p>
<p align="left"><font color="#800000" size="6" face="Tahoma"><img src="http://www.dirc-est.fr/AAP/logoThesaurus.png" alt="Thesaurus AAP" width="600" height="129" border="0"></font></p>
<p> </p>
<p id="info_date"></p>
</div>
</td>
</tr>
</tbody>
</table>
<table align=center border=1 bordercolor="#FFFFFF" cellpadding="6" cellspacing="2" width="91%" bgcolor="#FFFFFF">
<tr>
<td width="100%"><div align="justify">
<form name="form_recherche" method="post" action="rechercher.php" onsubmit="return valider();">
<div> <font style="font-size:12pt" face="TAHOMA" color="#800000"><b>
Votre Recherche :
<input type="text" name="recherche" /
<br />
<input type="submit" value="Rechercher" name="rechercher" />
</b></font>
<h2><font style="font-size:12pt" face="TAHOMA" color="#800000"><b>Type d'Appels à Projets</b></font></h2>
<INPUT TYPE="checkbox" NAME="Question1" VALUE="1" ID=Checkbox1 <?php echo"$q1checked";?>><font style="font-size:10pt" face="TAHOMA" color="#000000">Subventions de recherche</font><br>
<INPUT TYPE="checkbox" NAME="Question2" VALUE="2" ID=Checkbox2 <?php echo"$q2checked";?>><font style="font-size:10pt" face="TAHOMA" color="#000000">Bourses Jeunes Chercheurs</font><br>
<INPUT TYPE="checkbox" NAME="Question3" VALUE="3" ID=Checkbox3 <?php echo"$q3checked";?>><font style="font-size:10pt" face="TAHOMA" color="#000000">Prix récompensant un travail terminé</font><br>
</div>
</br>
<div align="left"> <font style="font-size:8pt" face="TAHOMA" color="#000000"><em> (vous pouvez cliquer sur les entêtes du tableau pour effectuer un tri) </em></font></div>
</form>
</div></td>
<td width="100%"><div align="right">
<h2><font style="font-size:12pt" face="TAHOMA" color="#000000"><b>les projets "cancer" sont recensés sur le site du cancéropôle </b></font></h2>
<div align="right"> <font style="font-size:8pt" face="TAHOMA" color="#000000"><em> (vous pouvez cliquer sur le lien ci-dessous pour les AAP en cancérologie) </em></font></div>
</br>
<a href="http://www.canceropole-ge.org/perl/dbcge/aap/Home" target="_blank"><img src="http://www.dirc-est.fr/images/logo-canceropole_grand_est.jpg" alt="AAP cancer" width="200" height="59" border="0" /></a></div></td>
<td width="131"> </td>
</tr>
</table>
<table style="margin-top:30px;" align=center border=1 bordercolor="#FFFFFF" cellpadding="6" cellspacing="2" class="sortable" width="92%">
<tr bgcolor="#cc6162" align="center">
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Spécialité</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Intitulé</b></font>
</td>
<td width="700" align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Description</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Organisme Emetteur</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Type</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Date Limite</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Montant (€)</b></font>
</td>
<td align="center" valign="middle">
<font style="font-size:10pt" face="TAHOMA" color="#FFFFFF"><b>Lien</b></font>
</td>
</tr>
<?php
$sql = "SELECT * FROM aap INNER JOIN organisme ON organisme_id=id_organisme INNER JOIN type_aap ON id_type=type_id INNER JOIN specialite ON id_specialite=specialite_id WHERE ($requete) AND ($requete2) ORDER BY date_fin ASC";
$req = mysql_query($sql);
while($data=mysql_fetch_array($req)){
$array_date_mysql=explode("-",$data['date_fin']);
if( empty($array_date_mysql[0]) && empty($array_date_mysql[1]) && empty($array_date_mysql[2]) ){
$date_fr = 'projet permanent';
$nomTab = 'tabWithDateNull';
}
else{
$date_fr=$array_date_mysql[2]."/".$array_date_mysql[1]."/".$array_date_mysql[0];
$nomTab = 'tabWithDateNotNull';
}
${$nomTab}[] = '
<tr align="center">
<td>
<font style="font-size:10pt" face="TAHOMA" color="#321000"><b>
'.$data['nom'].'
</b></font>
</td>
<td>
<font style="font-size:8pt" face="TAHOMA" color="#505050"><b>
'.$data['nom_aap'].'
</b></font>
</td>
<td>
<P align="justify">
<font style="font-size:8pt" face="TAHOMA" color="#505050">
'.nl2br($data['description']).'
</font>
</td>
<td>
<font style="font-size:8pt" face="TAHOMA" color="#505050"><b>
'.$data['nom_organisme'].'
</b></font>
</td>
<td>
<font style="font-size:6pt" face="TAHOMA" color="#505050"><b>
'.$data['nom_type'].'
</b></font>
</td>
<td>
<font style="font-size:6pt" face="TAHOMA" color="#505050"><b>
'.$date_fr.'
</b></font>
</td>
<td>
<font style="font-size:6pt" face="TAHOMA" color="#505050"><b>
'.nl2br ($data['montant']).'
</b></font>
</td>
<td>
<font style="font-size:8pt" face="TAHOMA" color="#505050"><b>
<a href="'.$data['lien_internet'].'" target="_blank" ><img src="http://www.dirc-est.fr/images/clic_test6.png " border="0" width="38" height="38" alt="lien"></a>
</b></font>
</td>
</tr>';
}
$tabAll = array_merge($tabWithDateNotNull, $tabWithDateNull);
foreach($tabAll as $elt){
echo($elt);
}
?>
</table>
</body>
<br/>
<div align="center"><font style="font-size:10pt" face="TAHOMA" color="#800000"><b>Mis à Jour le 29/03/2012</b></font></div>
<br/>
</html>
[/php]