1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| <h1>Instructions</h1>
<?php
mysql_connect('localhost','root','') or die(mysql_error());;
mysql_select_db('clients');
//On determine l'expression a rechercher
if(isset($_GET['recherche']))
{
$rec = htmlentities($_GET['recherche']);
}
else
{
$rec = 'php MYSQL';
}
//On determine le type de recherche
if(isset($_GET['type']))
{
if($_GET['type']=='un')//Un des mots
{
$type = 1;
}
elseif($_GET['type']=='tout')//Tout les mots
{
$type = 2;
}
else//L'expression exacte
{
$type = 3;
}
}
else
{
$type = 1;//type par defaut: L'expression exacte
}
//On determine si on doit surligner les mots dans les resultats
if(!isset($_GET['surligner']) or $_GET['surligner']!='true')
{
$surligner = false;
}
else
{
$surligner = true;
}
//On dertermine les identifiants, les noms et les informations des utilisateur
$req = 'SELECT RAISON SOCIALE, DIRIGEANT,ADRESSE, CP, REGION, VILLE, TEL, TELECOPIE, EMAIL, EMAIL2, CODE_NAF, LIBELLE_NAF, RUBRIQUE_PROFESSIONNELLE FROM list WHERE';
if($type==1)
{//ayant un des mots dans leurs informations
$mots = explode(' ',$rec);//En separre lexpression en mots cles
foreach($mots as $mot)
{
$req .= ' email LIKE "%'.$mot.'%" OR';
}
$req .= ' 1=1';
}
elseif($type==2)
{//ayant tout des mots dans leurs informations
$mots = explode(' ',$rec);//En separre lexpression en mots cles
foreach($mots as $mot)
{
$req .= ' email LIKE "%'.$mot.'%" AND';
}
$req .= ' 1=1';
}
else
{//ayant l'expression exacte dans leurs informations
$req .= 'email LIKE "%'.$rec.'%"';
}
//Les utilisateur seront ranges par identifiant en ordre croissant
$req .= ' order by username DESC';
//echo $req;
$requete = mysql_query($req);
//echo $requete;
//Le formulaire de recherche
?>
<form action="" method="get">
Expression à rechercher: <input type="text" name="recherche" value="<?php echo $rec; ?>" /><br />
Type de recherche: <input type="radio" name="type" value="un"<?php if($type==1){echo 'checked="checked"';} ?> /> Un des mots <input type="radio" name="type" value="tout"<?php if($type==2){echo 'checked="checked"';} ?> /> Tout les mots <br />
Mettre en gras les mots recherchés: <input type="checkbox" name="surligner" value="true" <?php if($surligner){echo 'checked="checked"';} ?> /><br />
<input type="submit" value="Rechercher" />
</form>
<h2>Résultats</h2>
<table>
<tr>
<th>Pseudo</th>
<th>Identifiant</th>
<th>email</th>
<th>Résumé</th>
<th> </th>
</tr>
<?php
//On affiche les resultats
while($dnn = mysql_fetch_array($requete))
{
?>
<tr>
<td><?php echo $dnn['username']; ?></td>
<td><?php echo $dnn['id']; ?></td>
<td><?php echo $dnn['email']; ?></td>
<td><b>|||</b> <?php
if($surligner)//Si il faut surligner les mots, on les surligne
{
if($type==3)
{
echo preg_replace('#('.preg_quote($rec).')#i', '<strong>$1</strong>', $dnn['infos']);//On surligne l'expression exacte
}
else
{
echo preg_replace('#('.str_replace(' ','|',preg_quote($rec)).')#i', '<strong>$1</strong>', $dnn['infos']);//On surligne les mots cles de la recherche
}
}
else
{
echo $dnn['username'];
echo $dnn['id'];
echo $dnn['email'];
}
//echo $requete
?></td>
</tr>
<?php
}
?>
<?php // ?>
</table> |
Partager