tabelrij kleuren op basis van variable
- alle data uit 1 databasetabel met 7 kolommen haalt;
- de data in een tabel zet;
- vervolgens kijkt naar de waarde van een bepaald veld in de database (genaamd: status);
- vervolgens op basis van die waarde (3 mogelijkheden: "nieuw", "klaar" of "in bewerking") de tabelrij in de output een bepaalde kleur geeft.
Ik heb al van alles geprobeert maar kom er als beginner niet uit. Heeft iemand een voorbeeld voor mij die eenvoudig aan te passen is?
Post je code tot nu toe eens.
Quote:
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
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
<?php
/* CONNECTION VARIABLES */
$db_hostname = "localhost"; // Usually "localhost"
$db_username = " ";
$db_password = " ";
$db_name = "werklijst";
$table = "werklijst";
$conn = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name, $conn) or die(mysql_error());
$display_block = "<h1>Server List</h1>";
$query = "SELECT zaaknummer, partijen, status FROM $table";
$result = @mysql_query($query) or die("Could not access database.");
$osColor = array(
'klaar' => '#B9D300',
'in bewerking' => '#F6D102',
'nieuw' => '#00CCFF'
);
while ($info = mysql_fetch_array($result)) {
$zaaknr = $info['zaaknummer'];
$partijen = $info['partijen'];
$status = $info['status'];
$color = (array_key_exists($status, $osColor)) ? $osColor[$status] : '#00CCFF';
$display_block .= "
<tr style='color: $color'>
<td align=\"center\">$zaaknr <br></td>
<td align=\"center\">$partijen <br></td>
<td align=\"center\">$os <br></td>
</tr>";
}
$display_block .= "</table>";
}
?>
/* CONNECTION VARIABLES */
$db_hostname = "localhost"; // Usually "localhost"
$db_username = " ";
$db_password = " ";
$db_name = "werklijst";
$table = "werklijst";
$conn = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name, $conn) or die(mysql_error());
$display_block = "<h1>Server List</h1>";
$query = "SELECT zaaknummer, partijen, status FROM $table";
$result = @mysql_query($query) or die("Could not access database.");
$osColor = array(
'klaar' => '#B9D300',
'in bewerking' => '#F6D102',
'nieuw' => '#00CCFF'
);
while ($info = mysql_fetch_array($result)) {
$zaaknr = $info['zaaknummer'];
$partijen = $info['partijen'];
$status = $info['status'];
$color = (array_key_exists($status, $osColor)) ? $osColor[$status] : '#00CCFF';
$display_block .= "
<tr style='color: $color'>
<td align=\"center\">$zaaknr <br></td>
<td align=\"center\">$partijen <br></td>
<td align=\"center\">$os <br></td>
</tr>";
}
$display_block .= "</table>";
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<style>
td.status.nieuw {
color:green;
}
td.status.oud {
color:red;
}
</style>
<td class="status <?php echo $status; ?>">
td.status.nieuw {
color:green;
}
td.status.oud {
color:red;
}
</style>
<td class="status <?php echo $status; ?>">
<html>
<head><title>Lijst</title></head>
<style>
td.status.nieuw {
color:green;
}
td.status.oud {
color:red;
}
</style>
<body>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$database="werklijst";
mysql_connect ("localhost", "", "");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT * FROM werklijst" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
$status = $result['status'];
print "There are $num_rows records.<P>";
print "<table width=400 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
$database="werklijst";
mysql_connect ("localhost", "", "");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT * FROM werklijst" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
$status = $result['status'];
print "There are $num_rows records.<P>";
print "<table width=400 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
</body>
</html>