Hij geeft tabel niet goed weer
<html>
<head>
<title>Stand in de eredivisie</title>
</head>
<body>
<table border="1" width="60%" align="center">
<tr>
<td colspan="20" align="center"><h2>De stand van week 52</h2></td>
</tr>
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
for($teller = 1; $teller <=18; $teller++){
$db['host'] = 'localhost';
$db['user'] = 'user';
$db['pass'] = 'password';
$db['name'] = 'name';
mysql_connect($db['host'],$db['user'],$db['pass']) ;
@mysql_select_db($db['name']) or die( "Unable to select database");
$query = "SELECT * FROM eredivisie ORDER BY punten";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo ("<td>$teller</td><td align=\"right\">".($row['club'])."</td><td>
".($row['aantal'])."</td><td>".($row['winst'])."</td><td>".($row['verlies'])."</td><td>".($row['gelijk'])."</td><td>".($row['punten'])."</td>
<td>".($row['dpvoor'])."</td><td>".($row['dptegen'])."</td><td>".($row['doelsaldo'])."</td></tr>");
}}
?>
for($teller = 1; $teller <=18; $teller++){
$db['host'] = 'localhost';
$db['user'] = 'user';
$db['pass'] = 'password';
$db['name'] = 'name';
mysql_connect($db['host'],$db['user'],$db['pass']) ;
@mysql_select_db($db['name']) or die( "Unable to select database");
$query = "SELECT * FROM eredivisie ORDER BY punten";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo ("<td>$teller</td><td align=\"right\">".($row['club'])."</td><td>
".($row['aantal'])."</td><td>".($row['winst'])."</td><td>".($row['verlies'])."</td><td>".($row['gelijk'])."</td><td>".($row['punten'])."</td>
<td>".($row['dpvoor'])."</td><td>".($row['dptegen'])."</td><td>".($row['doelsaldo'])."</td></tr>");
}}
?>
</table>
</body>
</html>
Het resultaat is te zien op:
http://aquauploads.aq.funpic.de/fotowedstrijd/test/tabel.php
Kan iemand naar die pagina kijken, en ik heb order by punten DESC er in gezet. Dat doet hij wel op twee clubs na, die zet hij gewoon ergens tussenin. Wat doe ik toch in hemelsnaam verkeerd?
Edit: Misschien kan die for() wel helemaal weg als je LIMIT 18 gaat gebruiken.
Gewijzigd op 30/12/2005 15:21:00 door - SanThe -
Je gebruikt nu 2 loops, daarom wordt alles 18x afgedrukt.
Is het veld 'punten' in je database trouwens wel van het type INTEGER? De sortering is nu niet goed.
<html>
<head>
<title>Stand in de eredivisie</title>
</head>
<body>
<table border="1" width="60%" align="center">
<tr>
<td colspan="20" align="center"><h2>De stand van week 52</h2></td>
</tr>
<tr><td bgcolor="#cccccc">Pos</td><td bgcolor="#cccccc">Club</td><td bgcolor="#cccccc">gespeeld</td><td bgcolor="#cccccc">winst</td><td bgcolor="#cccccc">gelijk</td><td bgcolor="#cccccc">verlies</td><td bgcolor="#cccccc">punten</td><td bgcolor="#cccccc">dpvoor</td><td bgcolor="#cccccc">dptegen</td><td bgcolor="#cccccc">doelsaldo</td></tr>
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
$db['host'] = 'localhost';
$db['user'] = 'user';
$db['pass'] = 'pass';
$db['name'] = 'name';
mysql_connect($db['host'],$db['user'],$db['pass']) ;
@mysql_select_db($db['name']) or die( "Unable to select database");
$query = "SELECT * FROM eredivisie ORDER BY punten DESC";
$result = mysql_query($query) or die(mysql_error());
for($teller = 1; $teller <=18; $teller++){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo ("<td>$teller</td><td align=\"right\">".($row['club'])."</td><td>
".($row['aantal'])."</td><td>".($row['winst'])."</td><td>".($row['gelijk'])."</td><td>".($row['verlies'])."</td><td>".($row['punten'])."</td>
<td>".($row['dpvoor'])."</td><td>".($row['dptegen'])."</td><td>".($row['doelsaldo'])."</td></tr>");
}}
?>
$db['host'] = 'localhost';
$db['user'] = 'user';
$db['pass'] = 'pass';
$db['name'] = 'name';
mysql_connect($db['host'],$db['user'],$db['pass']) ;
@mysql_select_db($db['name']) or die( "Unable to select database");
$query = "SELECT * FROM eredivisie ORDER BY punten DESC";
$result = mysql_query($query) or die(mysql_error());
for($teller = 1; $teller <=18; $teller++){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo ("<td>$teller</td><td align=\"right\">".($row['club'])."</td><td>
".($row['aantal'])."</td><td>".($row['winst'])."</td><td>".($row['gelijk'])."</td><td>".($row['verlies'])."</td><td>".($row['punten'])."</td>
<td>".($row['dpvoor'])."</td><td>".($row['dptegen'])."</td><td>".($row['doelsaldo'])."</td></tr>");
}}
?>
</table>
</body>
</html>
Zet vlak voor de while-loop $teller=0 en binnen de while-loop $teller++.
for($teller = 1; $teller <=18; $teller++){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
De for() gaat van 1 -> 18
De while loopt helemaal tot ie klaar is.
Dus dan pas zal de for() op 2 springen en dan doet de while() niks meer want die is al klaar.
Snappie?
Edit: Typo.
Gewijzigd op 30/12/2005 20:53:00 door - SanThe -
while ($teller = 1; $teller <=18; $teller++, $row = mysql_fetch_array($result, MYSQL_ASSOC)){
hij geeft dan ook een fout, unexpected ;
function teller_static(){
static $teller_static = 0;
$teller_static++;
echo($teller_static);
}
voor de for en while lus gebruik geeft hij wel 1-18, alleen dan niet in die rij die ervoor bestemd is, hij plaatst hm buiten de tabel.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
$query = "SELECT * FROM eredivisie ORDER BY punten DESC";
$result = mysql_query($query) or die(mysql_error());
$teller = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$teller++;
echo ("<td>$teller</td><td align=\"right\">".($row['club'])."</td><td>
".($row['aantal'])."</td><td>".($row['winst'])."</td><td>".($row['gelijk'])."</td><td>".($row['verlies'])."</td><td>".($row['punten'])."</td>
<td>".($row['dpvoor'])."</td><td>".($row['dptegen'])."</td><td>".($row['doelsaldo'])."</td></tr>");
}
?>
$query = "SELECT * FROM eredivisie ORDER BY punten DESC";
$result = mysql_query($query) or die(mysql_error());
$teller = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$teller++;
echo ("<td>$teller</td><td align=\"right\">".($row['club'])."</td><td>
".($row['aantal'])."</td><td>".($row['winst'])."</td><td>".($row['gelijk'])."</td><td>".($row['verlies'])."</td><td>".($row['punten'])."</td>
<td>".($row['dpvoor'])."</td><td>".($row['dptegen'])."</td><td>".($row['doelsaldo'])."</td></tr>");
}
?>
Ik ga helemaal met Burdy mee. Alleen moet je waarschijnlijk LIMIT 18 aan de query toevoegen.
Hardstikke bedankt Burdy, hij doet het. Thnx