[RESOLU] recherche LIKE

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] recherche LIKE

Re: [RESOLU] recherche LIKE

par moogli » 13 déc. 2013, 11:02

de rien :)

@+

Re: recherche LIKE

par acym » 12 déc. 2013, 23:37

Bonsoir

J'ai tout corrigé et cela fonctionne

Merci MOOGLI

Re: recherche LIKE

par acym » 12 déc. 2013, 23:32

bonsoir,
j'ai trouvé l’erreur et je passe bien par le IF, mais aucunes données s'affiches.


Merci

Re: recherche LIKE

par acym » 12 déc. 2013, 23:25

Bonsoir moogli,
j'ai fait les pages ajouter, afficher la liste des clients,
mais je ne sais pas quelle code pour faire une recherche avec LIKE.

Car le mot entré dans l'imput de la recherche ne passe pas par le il et va directement dans le else.

je te joint le fichier recherche
<?php
include('../config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>scoreboard</title>
<link href="Css/style.css" type="text/css" rel="stylesheet"/>
<link href="Css/menuPage.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="global">
	<div id="headerMenu">
		<div id="logo">
			<img src="../images/logo.jpg" width="100" height="56">
			<?php include_once'menuPage.php';?>
		</div><!-- end div logo-->
	</div><!-- end headerMenu -->
 	<div id="principale">
 	
 	<form method="POST" action="function_search.php">
 	<center>
 		Rechercher 
 		<input type="text" name="search" />
 		<select name="search_list">
 		<option value="dossier" selected="dossier">dossier</option>
 		<option value="type_societe" selected="type_societe">type_societe</option>
 		<option value="tache" selected="tache">tâche</option>
 		<option value="commentaire" selected="commentaire">commentaire</option>
 		<option value="" selected=""></option>
 			
 		</select>
 		<p>
 		<input type="submit" name="submit" value="Chercher" />
 		</center></p>
 	</form>
    
 	<!-- fin du texte -->
 	<div class="foot">
      <?php include('footerPage.php');?>      
        </div>
 	</div><!-- end div pricipale-->

</div><!-- end div global-->
</body>
</html>

et le fichier action
<?php
include('../config.php');



if($_POST['search_list']=='nom_dossier')
{
$search=$_POST['search'];
?>

<table width ='100%'>
	<tr>
	<td><b>nom_dossier</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>type_societe</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>collaborateur</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>date_cloture</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>type_mission</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>tâche</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>périodicité</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>date_échéance</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>quantité</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>avancement</b></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
	<td><b>commentaire</b></td>
	</tr>
<?php


$req = "select *  FROM excel WHERE nom_dossier LIKE '%.$search%' ";
$result_set=mysql_query($req);
while($dnn = mysql_fetch_array($result_set))
{
?>
	<tr>
    	<td class="left">
    	<?php echo htmlentities($dnn['nom_dossier'], ENT_QUOTES, 'UTF-8'); ?>
    	</a></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['type_societe'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['collaborateur'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['date_cloture'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['type_mission'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['tache'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['periodicite'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['date_echeance'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['quantite'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['avancement'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    	<td class="left"><?php echo htmlentities($dnn['commentaire'], ENT_QUOTES, 'UTF-8'); ?></td>
	<td>&nbsp;&nbsp;&nbsp;</td>
    <td>
    	<a href="afficher.php?id=<?php echo $dnn['id']; ?>">Modifier</a>
    </td>
    </tr>
<?php
}
}
else
{
	echo'Aucune correspondance avec votre recherche';
}
?>
MERCI

Re: recherche LIKE

par moogli » 12 déc. 2013, 23:18

salut,


ton code n'est pas syntaxiquement correct !
Récupérer les données d'un formulaire
afficher les données provenant d'une base mysql (le principe est le même pour toutes les bases, seule les noms de fonction change.

il y a tous ce qu'il te faut pour réussir ce que tu veux faire ;)


@+

recherche LIKE

par acym » 12 déc. 2013, 22:57

Bonjour,
je viens d'ajouter un input type texte pour faire une recherche dans ma base de données.
Mais ensuite comment faire pour dire à mysql de rechercher ce mot dans la base de données. et d'afficher ?

<form method="POST" action="function_search.php">
 	<center>
 		Rechercher 
 		<input type="text" name="search" />
 		<select name="search_list">
 		<option value="dossier" selected="dossier">dossier</option>
 		<option value="type_societe" selected="type_societe">type_societe</option>
 		<option value="tache" selected="tache">tâche</option>
 		<option value="commentaire" selected="commentaire">commentaire</option>
 		<option value="" selected=""></option>
 			
 		</select>
 		<p>
 		<input type="submit" name="submit" value="Chercher" />
 		</center>
Début de code
<?php
include('../config.php');

$search=$_POST['search'];

$sql = SELECT *
FROM excel
WHERE nom_dossier LIKE .$search;

?>
Merci