Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Graficzna prezentacja średniej wartości uzyskanej z 4 parametrów
php__amator
post
Post #1





Grupa: Zarejestrowani
Postów: 217
Pomógł: 1
Dołączył: 26.05.2011
Skąd: Moon

Ostrzeżenie: (10%)
X----


Witam,
Zapewne znowu się wygłupię pytając o tak błache rzeczy ale ... niech tam (IMG:style_emoticons/default/wink.gif)

otóż mam to w zasadzie zrobione od dawna ale strasznie "na około".
Skrypt odczytuje wartości 4 komórek z bazy i na ich podstawie wyświetla odpowiedni obrazek
prezentujący łagonie rzecz ujmując walory powiedzmy osobnika (IMG:style_emoticons/default/wink.gif) w postaci słupka (u podstawy zielony
i im wyższy tym bardziej czerwony (IMG:style_emoticons/default/wink.gif) (IMG:style_emoticons/default/smile.gif) (IMG:style_emoticons/default/smile.gif) ) ale mniejsza o szczegóły barwne,
rozwiązałem to ustawiając serię warunków "if"
  1. if ($eng <=0.5) {
  2. echo '<div class="oth" id="oth"><img src="images/1.png" width="8" height="78"></div>';
  3. }
  4. if ($eng >0.5 && $eng <=1.5) {
  5. echo '<div class="oth" id="oth"><img src="images/2.png" width="8" height="78"></div>';
  6. }
  7. if ($eng >1.5 && $eng <=2) {
  8. echo '<div class="oth" id="oth"><img src="images/3.png" width="8" height="78"></div>';
  9. }
  10. if ($eng >2 && $eng <=2.5) {
  11. echo '<div class="oth" id="oth"><img src="images/4.png" width="8" height="78"></div>';
  12. }
  13. if ($eng >2.5 && $eng <=3) {
  14. echo '<div class="oth" id="oth"><img src="images/5.png" width="8" height="78"></div>';
  15. }
  16. if ($eng >3 && $eng <=3.5) {
  17. echo '<div class="oth" id="oth"><img src="images/6.png" width="8" height="78"></div>';
  18. }
  19. if ($eng >3.5 && $eng <=4) {
  20. echo '<div class="oth" id="oth"><img src="images/7.png" width="8" height="78"></div>';
  21. }
  22. if ($eng >4 && $eng <=4.5) {
  23. echo '<div class="oth" id="oth"><img src="images/8.png" width="8" height="78"></div>';
  24. }
  25. if ($eng >4.5 && $eng <=5) {
  26. echo '<div class="oth" id="oth"><img src="images/9.png" width="8" height="78"></div>';
  27. }
  28. if ($eng >5 && $eng <=5.5) {
  29. echo '<div class="oth" id="oth"><img src="images/10.png" width="8" height="78"></div>';
  30. }
  31. if ($eng >5.5 && $eng <=6) {
  32. echo '<div class="oth" id="oth"><img src="images/11.png" width="8" height="78"></div>';
  33. }
  34. if ($eng >6 && $eng <=6.5) {
  35. echo '<div class="oth" id="oth"><img src="images/12.png" width="8" height="78"></div>';
  36. }
  37. if ($eng >6.5 && $eng <=8) {
  38. echo '<div class="oth" id="oth"><img src="images/13.png" width="8" height="78"></div>';
  39. }
  40. if ($eng >8 && $eng <=10) {
  41. echo '<div class="oth" id="oth"><img src="images/14.png" width="8" height="78"></div>';
  42. }
  43. }

Zdaję sobie sprawę, że można to zrobić inaczej, lepiej, krócej ale moja wiedza jest jeszcze zbyt ... ograniczona
żeby sobie z tym poradzić dlatego proszę o pomoc.
Chciałbym skrócić/usunąć zbędne rzeczy, uprościć kod, no chyba że się nie da (IMG:style_emoticons/default/smile.gif) ?

pozdrawiam
phpamator
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
red.orel
post
Post #2





Grupa: Zarejestrowani
Postów: 42
Pomógł: 9
Dołączył: 3.02.2012

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


  1. function getImage($eng)
  2. {
  3. if($eng <= 0.5)
  4. return 1;
  5. elseif($eng > 0.5 && $eng <= 1.5)
  6. return 2;
  7. elseif($eng > 6.5 && $eng <= 8)
  8. return 13;
  9. elseif($eng > 8 && $eng < 10)
  10. return 14;
  11. else
  12. {
  13. for($i = 1.5; $i <= 6; $i+=0.5)
  14. {
  15. if($eng > $i && $eng <= ($i + 0.5))
  16. return ($i*2);
  17. }
  18. }
  19.  
  20. return 0;
  21. }
  22.  
  23. function renderImage($eng)
  24. {
  25. echo '<div class="oth" id="oth"><img src="images/'.getImage($eng).'.png" width="8" height="78"></div>';
  26. }
  27.  
  28. renderImage($eng);


Powinno działać.

Ten post edytował red.orel 10.09.2012, 02:35:17
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: 2.10.2025 - 22:32