Achtergrond per <TR> in een Array
De onderstaande code geeft een tabel met rechten per module weer. Zowel de rechten, groupen en de modules worden hierbij uit mijn database gehaald. Nu wil ik per rij ( <tr> ) een achtergrondkleur toevoegen op de volgende manier: grijs, wit, grijs, wit etc... Hoe kan ik dit het beste doen? Ik zat zelf te denken om "->num_rows" te gebruiken. Ik geef dan elk even getal een grijze kleur en elk oneven getal een witte kleur. Wat denken jullie?
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
echo " <table style='border-style: solid; border-width: 1; border-color: #000000;'>";
echo " <tr>";
echo " <td>Groep</td><td colspan=4>Groep</td>";
$sql = "SELECT
m.*,
g.*,
r.*
FROM
modules AS m
INNER JOIN
k_acces AS a
ON
m.module_id = a.module_id
INNER JOIN
rights AS r
ON
m.module_id = a.module_id
INNER JOIN
groups AS g
ON
m.module_id = a.module_id
WHERE
g.group_id = a.group_id
AND
r.right_id = a.right_id
AND
a.module_id = $ModuleId
";
if(!$Srights = $mysqli->query($sql))
{
trigger_error('Fout in query: '.$mysqli->error);
}
else
{
while($row = $Srights->fetch_assoc())
{
echo " <tr>";
echo " <td width='100'>".$row['group_name']."</td>";
$sql = "SELECT * FROM rights ";
if(!$Sright = $mysqli->query($sql))
{
trigger_error('Fout in query: '.$mysqli->error);
}
else
{
while($row = $Sright->fetch_assoc())
{
echo " <td width='80' align='center'>".$row['right_name']."<br><input type='radio' name='right_id' value='".$row['right_id']."'></td>";
}
}
echo " </tr>";
}
}
echo " </table>";
?>
echo " <table style='border-style: solid; border-width: 1; border-color: #000000;'>";
echo " <tr>";
echo " <td>Groep</td><td colspan=4>Groep</td>";
$sql = "SELECT
m.*,
g.*,
r.*
FROM
modules AS m
INNER JOIN
k_acces AS a
ON
m.module_id = a.module_id
INNER JOIN
rights AS r
ON
m.module_id = a.module_id
INNER JOIN
groups AS g
ON
m.module_id = a.module_id
WHERE
g.group_id = a.group_id
AND
r.right_id = a.right_id
AND
a.module_id = $ModuleId
";
if(!$Srights = $mysqli->query($sql))
{
trigger_error('Fout in query: '.$mysqli->error);
}
else
{
while($row = $Srights->fetch_assoc())
{
echo " <tr>";
echo " <td width='100'>".$row['group_name']."</td>";
$sql = "SELECT * FROM rights ";
if(!$Sright = $mysqli->query($sql))
{
trigger_error('Fout in query: '.$mysqli->error);
}
else
{
while($row = $Sright->fetch_assoc())
{
echo " <td width='80' align='center'>".$row['right_name']."<br><input type='radio' name='right_id' value='".$row['right_id']."'></td>";
}
}
echo " </tr>";
}
}
echo " </table>";
?>
Code:
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jan Koehoorn | How to make a zebra table in PHP</title>
<link type="text/css" rel="stylesheet" media="screen" href="reset.css" />
<link type="text/css" rel="stylesheet" media="screen" href="oop.css" />
<style type="text/css">
div#container { width: 1000px; }
table { border-collapse: separate; border-spacing: 2px; width: 80%; margin: 0 auto; }
td { padding: 5px 10px; color: #fff; }
tr.bg0 { background: #bac; }
tr.bg1 { background: #cab; }
</style>
</head>
<body>
<div id="container">
<h1>How to make a zebra table in PHP</h1>
<table>
<?php
$flip = 0;
for ($i = 0; $i < 10; $i++) {
$flip ^= 1;
echo '<tr class="bg' . $flip . '">';
echo '<td>een</td>';
echo '<td>twee</td>';
echo '<td>drie</td>';
echo '<td>vier</td>';
echo '<td>vijf</td>';
echo '<tr>';
}
?>
</table>
<?php
require 'show_source.php';
?>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jan Koehoorn | How to make a zebra table in PHP</title>
<link type="text/css" rel="stylesheet" media="screen" href="reset.css" />
<link type="text/css" rel="stylesheet" media="screen" href="oop.css" />
<style type="text/css">
div#container { width: 1000px; }
table { border-collapse: separate; border-spacing: 2px; width: 80%; margin: 0 auto; }
td { padding: 5px 10px; color: #fff; }
tr.bg0 { background: #bac; }
tr.bg1 { background: #cab; }
</style>
</head>
<body>
<div id="container">
<h1>How to make a zebra table in PHP</h1>
<table>
<?php
$flip = 0;
for ($i = 0; $i < 10; $i++) {
$flip ^= 1;
echo '<tr class="bg' . $flip . '">';
echo '<td>een</td>';
echo '<td>twee</td>';
echo '<td>drie</td>';
echo '<td>vier</td>';
echo '<td>vijf</td>';
echo '<tr>';
}
?>
</table>
<?php
require 'show_source.php';
?>
</div>
</body>
</html>
Gewijzigd op 01/01/1970 01:00:00 door Jan Koehoorn
En dat terwijl ik de TERM NIET EENS KON !
http://wiki.phpfreakz.nl/Resultaat_in_rijen_met_om-en-om_wisselende_kleurtjes
:-)
Edit: Oh, lol, volgende keer verversen...
:-)
Edit: Oh, lol, volgende keer verversen...