Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Kolorowanie warunkowe w pętli z wynikami
f41t3r
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 7.03.2006

Ostrzeżenie: (0%)
-----


Mam problem z kolorowaniem wyników wyświetlanych przez skrypt mysql. Chodzi mi o to ażeby wiersze zawierające konkretne wartości tj. error, warning, critical itp. były innego odpowiedniego koloru.

Tak wygląda dotychdczasowy skrypt, który musze się przyznać, że nie działa za dobrze tj. podczas warunku cały czas zwraca wartość false i wykonuje mi tylko elsa czyli podkreśla wszystkie linie na #dddddd


  1. <?php
  2.  
  3.  
  4. @ $query="select * from syslogd.syslogd where
  5. MsgDate='".mysql_escape_string($HTTP_GET_VARS['bydate'])."' AND (Msghostname 
  6.  
  7. LIKE '".mysql_escape_string($HTTP_GET_VARS['Urzadzenie'])."' AND Msgpriority 
  8.  
  9. LIKE '".mysql_escape_string($HTTP_GET_VARS['priority1'])."' OR Msgpriority 
  10.  
  11. LIKE '".mysql_escape_string($HTTP_GET_VARS['priority2'])."' oR Msgpriority 
  12.  
  13. LIKE '".mysql_escape_string($HTTP_GET_VARS['priority3'])."' OR Msgpriority 
  14.  
  15. LIKE '".mysql_escape_string($HTTP_GET_VARS['priority4'])."' OR Msgpriority 
  16.  
  17. LIKE '".mysql_escape_string($HTTP_GET_VARS['priority5'])."') ORDER BY 
  18.  
  19. '".mysql_escape_string($HTTP_GET_VARS['order'])."'";
  20. $result=mysql_query("$query");
  21.  
  22. print "<table border=0>\n";
  23. print "<tr><td><a>Date</a></td><td><a >Time</a></td><td><a 
  24.  
  25. >Priority</a></td><td><a >Hostname</a></td><td><a>Text</a></td></tr>";
  26. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  27. print "\t<tr>\n";
  28. foreach ($line as $col_value) {
  29. print "\t<td bgcolor=";
  30.  
  31. if ($col_value=="%Alert%") {
  32. print "#DD8787";
  33. } 
  34.  
  35. elseif ($col_value=="%Emergency%"){
  36. print "#DD6767";
  37. }
  38.  
  39. elseif ($col_value=="%Critical%"){
  40. print "#DD5757";
  41. }
  42.  
  43. elseif ($col_value=="%Error%"){
  44. print "#87DD91";
  45. }
  46.  
  47. elseif ($col_value=="%Warning%"){
  48. print "#FEFF87";
  49. }
  50.  
  51.  
  52. else {
  53. print "#dddddd";
  54. };
  55.  
  56.  
  57. print ">$col_value</td>\n";
  58. }
  59. print "\t</tr>\n";
  60. }
  61. print "</table>\n";
  62.  
  63. ?>


Jak na razie utknąłem i nie wiem co dalej z tym zrobić.
Proszę o pomoc.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 16:05