 |
TemplatePower Forum Ask your question about TemplatePower here!
|
| View previous topic :: View next topic |
| Author |
Message |
kierownik
Joined: 15 Feb 2006 Posts: 2
|
Posted: Wed Feb 15, 2006 10:19 pm Post subject: while loop gets broken off |
|
|
Hi,
I have the next code that should work but it does't.
I have 12 members in the table teamleden but he only shows me 1 with his/her stats.
can you help me?
| Code: |
$tpl->newBlock('teamleden');
$result = $sql->query("SELECT * FROM teamleden order by gebruikersnaam ASC");
while ($data = $sql->fetch($result))
{
$tpl->newBlock("teamleden_while");
$tpl->assign('teamleden_while.gebruikersnaam', $data['gebruikersnaam']);
$tpl->assign('teamleden_while.actief', $data['actief']);
$stats1 = $sql->query("SELECT SUM(gewonnen) AS gewonnen, SUM(verloren) AS verloren, SUM(gelijk) AS gelijk FROM teamspelen WHERE gebruikersnaam = '".$data['gebruikersnaam']."'");
$stats = $sql->fetch($stats1);
$tpl->assign('teamleden_while.gewonnen', $stats['gewonnen']);
$tpl->assign('teamleden_while.verloren', $stats['verloren']);
$tpl->assign('teamleden_while.gelijk', $stats['gelijk']);
$totaal = $stats['gewonnen'] + $stats['verloren'] + $stats['gelijk'];
$tpl->assign('teamleden_while.totaal', $totaal);
$proc_gewonnen = ($stats['gewonnen'] / $totaal)*100;
$tpl->assign('teamleden_while.proc_gewonnen', ROUND($proc_gewonnen,2));
$proc_verloren = ($stats['verloren'] / $totaal)*100;
$tpl->assign('teamleden_while.proc_verloren', ROUND($proc_verloren,2));
$proc_gelijk = ($stats['gelijk'] / $totaal)*100;
$tpl->assign('teamleden_while.proc_gelijk', ROUND($proc_gelijk,2));
}
|
if i take out the next code out of the script it will show me all of the members.
| Code: |
$stats1 = $sql->query("SELECT SUM(gewonnen) AS gewonnen, SUM(verloren) AS verloren, SUM(gelijk) AS gelijk FROM teamspelen WHERE gebruikersnaam = '".$data['gebruikersnaam']."'");
$stats = $sql->fetch($stats1);
$tpl->assign('teamleden_while.gewonnen', $stats['gewonnen']);
$tpl->assign('teamleden_while.verloren', $stats['verloren']);
$tpl->assign('teamleden_while.gelijk', $stats['gelijk']);
$totaal = $stats['gewonnen'] + $stats['verloren'] + $stats['gelijk'];
$tpl->assign('teamleden_while.totaal', $totaal);
$proc_gewonnen = ($stats['gewonnen'] / $totaal)*100;
$tpl->assign('teamleden_while.proc_gewonnen', ROUND($proc_gewonnen,2));
$proc_verloren = ($stats['verloren'] / $totaal)*100;
$tpl->assign('teamleden_while.proc_verloren', ROUND($proc_verloren,2));
$proc_gelijk = ($stats['gelijk'] / $totaal)*100;
$tpl->assign('teamleden_while.proc_gelijk', ROUND($proc_gelijk,2));
|
the html code is:
| Code: |
<!-- START BLOCK : teamleden_while -->
<tr>
<td>
<a title="Externe link naar de gebruikerspagina van {gebruikersnaam} op jijbent.nl" href="http://jijbent.nl/user.php?username={gebruikersnaam}" target="_blank">{gebruikersnaam}</a>
</td>
<td style="text-align:center;">
{actief}
</td>
<td style="text-align:center;">
{gewonnen}
</td>
<td style="text-align:center;">
{verloren}
</td>
<td style="text-align:center;">
{gelijk}
</td>
<td style="text-align:center;">
{totaal}
</td>
<td style="text-align:center;">
{proc_gewonnen}%
</td>
<td style="text-align:center;">
{proc_verloren}%
</td>
<td style="text-align:center;">
{proc_gelijk}%
</td>
</tr>
<!-- END BLOCK : teamleden_while -->
|
I hope you can help me. |
|
| Back to top |
|
 |
Donny_nl
Joined: 11 Jan 2006 Posts: 14
|
Posted: Sun Mar 05, 2006 5:05 pm Post subject: |
|
|
He Kierowniek,
I don't see anything wrong with your code, but maybe there's something wrong with the sequence.
Anyway, i adjusted somethings, but the basics are still the same.
| Code: | $tpl->newBlock('teamleden');
$result = $sql->query("SELECT * FROM teamleden order by gebruikersnaam ASC");
while ($data = $sql->fetch($result))
{
$sql = "SELECT SUM(gewonnen) AS gewonnen,
SUM(verloren) AS verloren,
SUM(gelijk) AS gelijk
FROM teamspelen
WHERE gebruikersnaam = '".$data['gebruikersnaam']."'";
$stats1 = $sql->query($sql);
$stats = $sql->fetch($stats1);
$totaal = $stats['gewonnen'] + $stats['verloren'] + $stats['gelijk'];
$proc_gewonnen = ($stats['gewonnen'] / $totaal)*100;
$proc_verloren = ($stats['verloren'] / $totaal)*100;
$proc_gelijk = ($stats['gelijk'] / $totaal)*100;
$tpl->newBlock("teamleden_while");
$tpl->assign( Array( "gebruikersnaam" => $data['gebruikersnaam'],
"actief" => $data['actief'],
"gewonnen" => $stats['gewonnen'],
"verloren" => $stats['verloren'],
"gelijk" => $stats['gelijk'],
"totaal" => $totaal,
"proc_gewonnen" => round($proc_gewonnen,2),
"proc_verloren" => round($proc_verloren,2),
"proc_gelijk" => round($proc_gelijk,2)
));
} |
|
|
| Back to top |
|
 |
kierownik
Joined: 15 Feb 2006 Posts: 2
|
Posted: Tue Mar 07, 2006 8:23 pm Post subject: |
|
|
I asked somewhere else and they made this for me that woks just fine .
.php
| Code: |
$columns = 10;
$query = "SELECT DISTINCT spel_nr
FROM teamspelen
ORDER BY id ASC";
$result =$sql->query($query);
//we add this line because we need to know the number of rows
$num_rows = $sql->numRows($result);
$tpl->newBlock("ingevulde_teamspelen_test");
//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
$row = $sql->fetch($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
$tpl->newBlock("ingevulde_teamspelen_test1");
}
$tpl->newBlock("ingevulde_teamspelen_test2");
$tpl->assign('spelnr1', $row['spel_nr']);
//echo "<TD>" . $row['spel_nr'] . "</TD>\n";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
}
|
.tpl
| Code: |
<!-- START BLOCK : ingevulde_teamspelen_test -->
<center>
<table class="border_dashed" width="99%">
<tr style="background-color:#66CCFF;">
<td colspan="50" style="text-align:center;"><u><b>Spelnummers</b></u></td>
</tr>
<!-- START BLOCK : ingevulde_teamspelen_test1 -->
<tr>
<!-- START BLOCK : ingevulde_teamspelen_test2 -->
<td style="text-align:center;"><a href="{pad}ingevulde_teamspelen.php?spelnummer={spelnr1}">{spelnr1}</a></td>
<!-- END BLOCK : ingevulde_teamspelen_test2 -->
</tr>
<!-- END BLOCK : ingevulde_teamspelen_test1 -->
</table>
</center>
<!-- END BLOCK : ingevulde_teamspelen_test -->
| [/code] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|