Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Przemienne kolory rekordów w tabeli
eurosoft
post
Post #1





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 5.11.2010

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


w jaki sposób można zrobić przemienne kolorowanie kolejnych rekordów w tabeli?
Poniżej fragment kodu generującego tabelę:

  1. ...
  2. echo "<th>Ilość</th>";
  3. echo "<th>Osoba wpisująca</th>";
  4. echo "<th>Info</th>";
  5.  
  6. while($r = mysql_fetch_array($result) and $z = mysql_fetch_array($result1))
  7.  
  8. {
  9. echo "<tr>";
  10. echo "<td width=40 align=center>".$r[0]."</td>";
  11. echo "<td width=140>".$r[1]."</td>";
  12. echo "<td width=50 align=center>".$r[2]."</td>";
  13. echo "<td width=60 align=center>".$r[3]."</td>";
  14.  
  15. ....


Ten post edytował eurosoft 9.11.2010, 09:01:16
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Ghost_78
post
Post #2





Grupa: Zarejestrowani
Postów: 222
Pomógł: 34
Dołączył: 3.11.2010

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


najprosciej tak:
  1. $i=0;
  2. while($r = mysql_fetch_array($result) and $z = mysql_fetch_array($result1)){
  3. if ($i==0){
  4. $color='background-color: red;';
  5. $i=1;
  6. }else{
  7. $color='background-color: green;';
  8. $i=0;
  9. }
  10. echo "<tr style=\"$color\">";
  11. echo "<td width=40 align=center>".$r[0]."</td>";
  12. echo "<td width=140>".$r[1]."</td>";
  13. echo "<td width=50 align=center>".$r[2]."</td>";
  14. echo "<td width=60 align=center>".$r[3]."</td>";
Go to the top of the page
+Quote Post
phpion
post
Post #3





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Cytat(Ghost_78 @ 9.11.2010, 09:04:25 ) *
najprosciej tak:

Nie, najprościej tak:
http://www.w3.org/Style/Examples/007/evenodd.html
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: 11.10.2025 - 17:35