Surligner résultats dans mon tableau
Résolu/Fermé
augustin78
Messages postés
56
Date d'inscription
vendredi 9 janvier 2009
Statut
Membre
Dernière intervention
13 mai 2016
-
29 mars 2013 à 21:16
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 - 31 mars 2013 à 21:19
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 - 31 mars 2013 à 21:19
Bonjour à tous, j'effectue une recherche sql et je présente mes résultats sous forme de tableau:
echo '<td height="22"> </td><td valign="top">'.$row['nom'].' </td><td> </td><td valign="top">'.$row['phrase'].' </tr>';
J'ai 5 variables et j'aimerai faire une recherche dans la colonne phrase pour surligner ces variables qui sont des chaines de caractères je le précise si elles sont présentes dans ma colonne phrase. Merci d'avance.
echo '<td height="22"> </td><td valign="top">'.$row['nom'].' </td><td> </td><td valign="top">'.$row['phrase'].' </tr>';
J'ai 5 variables et j'aimerai faire une recherche dans la colonne phrase pour surligner ces variables qui sont des chaines de caractères je le précise si elles sont présentes dans ma colonne phrase. Merci d'avance.
A voir également:
- Surligner résultats dans mon tableau
- Tableau croisé dynamique - Guide
- Tableau word - Guide
- Tableau ascii - Guide
- Lexer resultats - Télécharger - Sport
- Trier tableau excel - Guide
3 réponses
Alain_42
Messages postés
5361
Date d'inscription
dimanche 3 février 2008
Statut
Membre
Dernière intervention
13 février 2017
894
30 mars 2013 à 08:58
30 mars 2013 à 08:58
salut, essaies comme ça:
<?php $phrase=$row['phrase']; $patterns = array(); $patterns[0] = '/'.$var1.'/'; $patterns[1] = '/'.$var2.'/'; $patterns[2] = '/'.$var3.'/'; $patterns[3] = '/'.$var4.'/'; $patterns[4] = '/'.$var5.'/'; $replacements = array(); $replacements[0] = '<u>'.$var1.'</u>'; $replacements[1] = '<u>'.$var2.'</u>'; $replacements[2] = '<u>'.$var3.'</u>'; $replacements[3] = '<u>'.$var4.'</u>'; $replacements[4] = '<u>'.$var5.'</u>'; /tu peux mettre en plus si tu veux <b></b> ou <strong>... $phase_soulignee= preg_replace($patterns, $replacements, $phrase); echo '<td height="22"> </td><td valign="top">'.$row['nom'].' </td><td> </td><td valign="top">'.$phase_soulignee.' </tr>';
augustin78
Messages postés
56
Date d'inscription
vendredi 9 janvier 2009
Statut
Membre
Dernière intervention
13 mai 2016
Modifié par augustin78 le 30/03/2013 à 12:41
Modifié par augustin78 le 30/03/2013 à 12:41
Bonjour Alain,
j'ai tenté comme tu m'as dit mais ça ne marche pas, sans doutes une erreur de ma part: voici un bout de code plus long:
je précise que des fois mes variables $Sympt1 ou 2 ou 3 peuvent être vide je sais pas si ça peut empêcher le remplacement...
j'ai tenté comme tu m'as dit mais ça ne marche pas, sans doutes une erreur de ma part: voici un bout de code plus long:
<?php if ($requete) { echo <<<'HTML' <p align=center> <table width=700 border=0 cellpadding=0 cellspac ing=0> <tr> <td width=150 height=19> </td> <td width=100> </td> <td width=9> </td> <td width=5000> </td> <td width=12> </td> <td width=124> </td> <td width=20> </td> </tr> <tr> <td height=22> </td> <td valign=top style="background-image: url(ok.png);"><b><p align=center>NOM</p></b> </td> <td> </td> <td valign=top style="background-image: url(ok.png);"><b><p align=center>NOMBRE DE SYMPTÔMES</p></b> </td> <td> </td> <td> </td> </tr> <tr> <td height=22> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> HTML; while ($row = mysql_fetch_array($requete)) { echo <<<HTML <td height="22"> </td> <td valign="top">{$row['nom']}</td> <td> </td> <td valign="top">{$row['symptomes']}</td> </tr> HTML; } echo <<<'HTML' <tr> <td height="157"> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> </p> <div> HTML; // ici tu es en dehors du while() alors $row = dernier enregistrement de $requete, c'est normal ? // relis les explications de sabotage tu devrais y arriver $phrase = $row['symptomes']; $patterns = array(); $patterns[0] = '/'.$Sympt1.'/'; $patterns[1] = '/'.$Sympt2.'/'; $patterns[2] = '/'.$Sympt3.'/'; $patterns[3] = '/'.$Sympt4.'/'; $patterns[4] = '/'.$Sympt5.'/'; $replacements = array(); $replacements[0] = '<span style="background-color:red;">'.$Sympt1.'</span>'; $replacements[1] = '<span style="background-color:red;">'.$Sympt2.'</span>'; $replacements[2] = '<span style="background-color:red;">'.$Sympt3.'</span>'; $replacements[3] = '<span style="background-color:red;">'.$Sympt4.'</span>'; $replacements[4] = '<span style="background-color:red;">'.$Sympt5.'</span>'; $phase_soulignee= preg_replace($patterns, $replacements, $phrase); }
je précise que des fois mes variables $Sympt1 ou 2 ou 3 peuvent être vide je sais pas si ça peut empêcher le remplacement...
Alain_42
Messages postés
5361
Date d'inscription
dimanche 3 février 2008
Statut
Membre
Dernière intervention
13 février 2017
894
31 mars 2013 à 21:19
31 mars 2013 à 21:19
oui c'est possible ?
alors essaies comme ça:
alors essaies comme ça:
$phrase = $row['symptomes']; $patterns = array(); $replacements = array(); $i=0; if($Sympt1 !=""){ $patterns[$i] = '/'.$Sympt1.'/'; $replacements[$i] = '<span style="background-color:red;">'.$Sympt1.'</span>'; $i++; } if($Sympt2 !=""){ $patterns[$i] = '/'.$Sympt2.'/'; $replacements[$i] = '<span style="background-color:red;">'.$Sympt2.'</span>'; $i++; } if($Sympt3 !=""){ $patterns[$i] = '/'.$Sympt3.'/'; $replacements[$i] = '<span style="background-color:red;">'.$Sympt3.'</span>'; $i++; } if($Sympt4 !=""){ $patterns[$i] = '/'.$Sympt4.'/'; $replacements[$i] = '<span style="background-color:red;">'.$Sympt4.'</span>'; $i++; } if($Sympt5 !=""){ $patterns[$i] = '/'.$Sympt5.'/'; $replacements[$i] = '<span style="background-color:red;">'.$Sympt5.'</span>'; $i++; } $phase_soulignee= preg_replace($patterns, $replacements, $phrase);