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
 
Start new topic
Odpowiedzi
f41t3r
post
Post #2





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

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


Cytat
2. Po co ta "małpa": 


A po to żeby mi brzydkich Notice-ów nie wyświetlał

Cytat
3. Czy na prawde potrzebujesz tak komplikować zapytanie:


Póki sie nie wymyśli czegoś wydajniejszego to raczej tak

Cytat
być może nie ma tam wartości typu %Error% tylko jakieś całkiem inne 


Niestety są (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

Kod

(...)


Array ( [MsgDate] => 2006-02-27 [MsgTime] => 05:36:42 [MsgPriority] => Local7.Error [MsgHostname] => hpr-s10 [MsgText] => %LINK-3-UPDOWN: Interface FastEthernet0/19, changed state to down ) Array ( [MsgDate] => 2006-02-27 [MsgTime] => 05:36:44 [MsgPriority] => Local7.Error [MsgHostname] => hpr-s10 [MsgText] => %LINK-3-UPDOWN: Interface FastEthernet0/19, changed state to up ) Array ( [MsgDate] => 2006-02-27 [MsgTime] => 05:37:12 [MsgPriority] =>


(...)


P.S. switcha zrobiłem no i wygląda faktycznie troche bardziej przejrzyście.

Pozdro.
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 4.10.2025 - 13:19