PHP-code:
<html>
<head>
<title>Gastenboek</title>
<link href="../css/standaard.css" rel="stylesheet" type="text/css">
</head>
<body>
<h3><center>Stemresultaten</center></h3>
<?php
// Beoordelingsoverzicht
include("../connect.php");
// Haal het totaal aantal stemmen en het grootste aantal stemmen uit de database
$sql = "SELECT SUM(stemmen) AS aantal, MAX(stemmen) AS maximum FROM votes";
$res = mysql_query($sql) or die(mysql_error());
$aantal = mysql_result($res, 0, "aantal");
$maximum = mysql_result($res, 0, "maximum");
if ($aantal > 0)
{
// Haal de cijfers uit de database met een join-query
$sql = "SELECT cijfer, stemmen FROM votes ORDER BY cijfer ASC";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) > 0)
{
// De maximumbreedte van een staafje
$max_width = 200;
$max_perc = $maximum / $aantal;
$factor = $max_width / $max_perc;
echo "<table border=0 cellspacing=0 cellpadding=0 width=\"400\">\n";
while ($row = mysql_fetch_object($res))
{
/* Bereken het percentage van het totaal aantal stemmen. */
$perc = $row->stemmen / $aantal;
$width = round($perc * $factor);
/* Laat nu de output zien. */
echo "<tr>\n";
echo "<td valign=\"top\">$row->cijfer </td>\n";
echo "<td valign=\"top\"><img src=\"pixel.gif\" width=\"$width\" height=\"10\"></td>\n";
echo "<td valign=\"top\">".round($perc * 100)."%</td>\n";
echo "</tr>\n";
$totaal = $totaal + $row->cijfer * $row->stemmen;
}
$gemcijfer = round(($totaal / $aantal),1);
echo "<tr>\n";
echo "<td valign=\"top\"></td>\n";
echo "<td valign=\"top\"><b>gemiddelde: $gemcijfer</b></td>\n";
echo "</tr>\n";
echo "</table>\n";
}
else
{
echo "Geen cijfers beschikbaar.";
}
}
else
{
echo "Er is nog niet gestemd.";
}
?>
<br>
<table align="center" cellpadding="4" border="1" width="80%">
<tr>
<td bgcolor="black">DATUM</td>
<td bgcolor="black">NAAM</td>
<td bgcolor="black">CIJFER</td>
<td bgcolor="black">REACTIE</td>
</tr>
<?php
include("../connect.php");
$sql="SELECT DATE_FORMAT(datum,'%d-%m-%y') AS stringdatum, naam, cijfer, reactie FROM gastenboek ORDER by datum DESC";
$res=mysql_query($sql, $db);
while ($ligne = mysql_fetch_object ($res))
{
print "<tr>";
print "<td><nobr>$ligne->stringdatum</nobr></td>";
print "<td>$ligne->naam</td>";
$ligne->cijfer = str_replace("0","-",$ligne->cijfer);
$ligne->cijfer = str_replace("1-","10",$ligne->cijfer);
print "<td><center>$ligne->cijfer</center></td>";
print "<td>$ligne->reactie</td>";
print "</tr>";
}
mysql_free_result ($res);
mysql_close($db);
?>
</table>
</body>
foutmelding:
Warning: main(): Unable to access ../../connect.php in /home/virtual/site110/fst/var/www/html/gastenboek/gastenboek.php on line 22
Warning: main(../../connect.php): failed to open stream: No such file or directory in /home/virtual/site110/fst/var/www/html/gastenboek/gastenboek.php on line 22
Warning: main(): Failed opening '../../connect.php' for inclusion (include_path='.:/php/includes:/usr/share/php') in /home/virtual/site110/fst/var/www/html/gastenboek/gastenboek.php on line 22
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site110/fst/var/www/html/gastenboek/gastenboek.php on line 24
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/virtual/site110/fst/var/www/html/gastenboek/gastenboek.php on line 25
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/virtual/site110/fst/var/www/html/gastenboek/gastenboek.php on line 33
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site110/fst/var/www/html/gastenboek/gastenboek.php on line 34
lijn 22 is
PHP-code:
$maximum = mysql_result($res, 0, "maximum");