Row kleur wijzigen gebaseerd op value
Ik heb in mijn php code de volgende style
<style>
td{
color: black;
width: 100px;
background-color: #ceDDce;
height: 50px;
text-align: center;
En dan bij de table:
echo'<td>'.$row['geslacht'].'</td>
Nu zou ik graag een verschillende kleuren willen afgaande op de value van de inhoud van "geslacht", dus meisje = roze , jongen = blauw , onbekend = groen
Is dit mogelijk ?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Je kijkt wat het geslacht is en geeft als het man is de class man mee.
<td class="<?= $row['geslacht'] == 'man' ? 'man' : 'vrouw')">
In je CSS defineer dan je een class die de background overruled
.man
{
background: blue!important;
}
.vrouw
{
background: pink!important;
}
<td class="<?= $row['geslacht'] == 'man' ? 'man' : 'vrouw')">
In je CSS defineer dan je een class die de background overruled
.man
{
background: blue!important;
}
.vrouw
{
background: pink!important;
}
Thks zover, en met drie opties, hoe wordt dan de regel ?
Code (php)
Code (php)
1
<td class="<?php echo $row['geslacht'] == 'man' ? 'man' : $row['geslacht'] == 'vrouw' ? 'vrouw' : 'anders'; ?>">
Zo kan het met drie en dit kun je natuurlijk nog veelmeer uitbereiden.
Gewijzigd op 27/10/2014 14:53:51 door Daan Slagter
td{
color: black;
width: 100px;
background-color: #ceDDce;
height: 50px;
text-align: center;
}
td.man{
color: black;
width: 100px;
background-color: #ceBBce!important;
height: 50px;
text-align: center;
}
td.vrouw{
color: black;
width: 100px;
background-color: #ceAAce!important;
height: 50px;
text-align: center;
en
<td class="
Gewijzigd op 27/10/2014 15:02:10 door Peter Penquin
er staat
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
td{
color: black;
width: 100px;
background-color: #ceDDce;
height: 50px;
text-align: center;
}
td.man{
color: black;
width: 100px;
background-color: #ceBBce!important;
height: 50px;
text-align: center;
}
td.vrouw{
color: black;
width: 100px;
background-color: #ceAAce!important;
height: 50px;
text-align: center;
?>
td{
color: black;
width: 100px;
background-color: #ceDDce;
height: 50px;
text-align: center;
}
td.man{
color: black;
width: 100px;
background-color: #ceBBce!important;
height: 50px;
text-align: center;
}
td.vrouw{
color: black;
width: 100px;
background-color: #ceAAce!important;
height: 50px;
text-align: center;
?>
En dan
code staat er niet maar ik krijg het niet weg
Op bovenstaande ktijg ik een error
Gewijzigd op 27/10/2014 15:20:27 door Peter Penquin
Omdat om je td geen
Code (php)
1
2
3
2
3
<?php moet zetten want dat is geen php code.
Post ander iets meer van je code dan aleen deze regel?
Post ander iets meer van je code dan aleen deze regel?
Gewijzigd op 27/10/2014 15:25:09 door Daan Slagter
De style tekst staat ook in de php pagina onder
<body>
<style>
textarea, input, button,
a, td, span{
font-family: "Trebuchet MS", Helvetica, sans-serif;
}
td{
color: black;
width: 100px;
background-color: #ceDDce;
height: 50px;
text-align: center;
}
td.jongen{
color: black;
width: 100px;
background-color: #ceBBce!important;
height: 50px;
text-align: center;
}
td.meisje{
color: black;
width: 100px;
background-color: #ceAAce!important;
height: 50px;
text-align: center;
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<?php
echo'<tr>
<td>'.$row['ID'].'</a></td>
<td>'.$row['NAAM'].'</td>
<td>'.$row['GESLACHT'].'</td>
<td>'.$row['BLA'].'</td>
<td>'.$row['BLA'].'</td>
echo'</tr>';
?>
echo'<tr>
<td>'.$row['ID'].'</a></td>
<td>'.$row['NAAM'].'</td>
<td>'.$row['GESLACHT'].'</td>
<td>'.$row['BLA'].'</td>
<td>'.$row['BLA'].'</td>
echo'</tr>';
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<body>
<style>
textarea, input, button,
a, td, span{
font-family: "Trebuchet MS", Helvetica, sans-serif;
}
td{
color: black;
width: 100px;
background-color: #ceDDce;
height: 50px;
text-align: center;
}
td.jongen{
color: black;
width: 100px;
background-color: #ceBBce!important;
height: 50px;
text-align: center;
}
td.meisje{
color: black;
width: 100px;
background-color: #ceAAce!important;
height: 50px;
text-align: center;
<style>
textarea, input, button,
a, td, span{
font-family: "Trebuchet MS", Helvetica, sans-serif;
}
td{
color: black;
width: 100px;
background-color: #ceDDce;
height: 50px;
text-align: center;
}
td.jongen{
color: black;
width: 100px;
background-color: #ceBBce!important;
height: 50px;
text-align: center;
}
td.meisje{
color: black;
width: 100px;
background-color: #ceAAce!important;
height: 50px;
text-align: center;
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<?php
echo'<tr>
<td>'.$row['ID'].'</a></td>
<td>'.$row['NAAM'].'</td>
<td class="'. $row['geslacht'] == 'jongen' ? 'jongen' : 'meisje' .'">'.$row['GESLACHT'].'</td>
<td>'.$row['BLA'].'</td>
<td>'.$row['BLA'].'</td>
</tr>';
?>
echo'<tr>
<td>'.$row['ID'].'</a></td>
<td>'.$row['NAAM'].'</td>
<td class="'. $row['geslacht'] == 'jongen' ? 'jongen' : 'meisje' .'">'.$row['GESLACHT'].'</td>
<td>'.$row['BLA'].'</td>
<td>'.$row['BLA'].'</td>
</tr>';
?>
Gewijzigd op 27/10/2014 15:54:02 door Daan Slagter
dan krijg ik een rare layout
Toevoeging op 27/10/2014 17:33:57:
Maar met bovenstaande verander ik alleen die ene "cel", ik wil eigenlijk dat de hele rij verandert van kleur.
Moet ik dan eigenlijk niet iets maken van:
<tr>
<td class="'. $row['geslacht'] == 'jongen' ? 'jongen' : 'meisje' .'">
en dan voor elke .$row
ipv <td> <td class> ?