Hallo allemaal,
Ik heb een probleem met smarty.
Ik heb een foreach met $i--; erin.
Als ik dit probeer:
index.php
PHP
<?php
// Copyright Messinagame 2011
// Created by Youri van Mill
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/configuration.php';
if(!isset($_SESSION['name']))
{
header('location: /login.php');
die;
}
$smarty = new Smarty();
$smarty->template_dir = 'inc/templates/';
$smarty->compile_dir = 'inc/templates/compile';
$smarty->config_dir = 'inc/templates/configs';
$smarty->cache_dir = 'inc/templates/cache';
$smarty->assign('name', $session['name']);
$max_items = 2;
$begin = ($_GET['p'] >= 0) ? $_GET['p'] * $max_items : 0;
// Create the first query
$stmt = $dbh->query('SELECT *
FROM ' . NEWS_TABLE . '
ORDER BY `date` ASC
LIMIT ' . $begin . ', ' . $max_items);
$result = array();
while($res = $stmt->fetch(PDO::FETCH_ASSOC))
{
$result[] = $res;
}
$smarty->assign('result', $result);
// End the first query
$stmt = null;
// Create the second query
$stmt = $dbh->query('SELECT *
FROM ' . NEWS_TABLE);
$smarty->assign('navigation', range(1, ceil($stmt->rowCount() / $max_items)));
// End the second query
$stmt = null;
$smarty->display('index.tpl');
?>
Toon Meer
index.tpl
PHP
<!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>
xxxx
</title>
<link rel="stylesheet" href="/static/style/style.css" type="text/css" />
<link rel="stylesheet" href="/static/style/tooltip.css" type="text/css" />
<script src="/static/js/functions.js" type="text/javascript"></script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="width:14%;vertical-align:top;">
{include file='menu-left.tpl'}
</td>
<td style="width:72%;vertical-align:top;">
<table style="border:none;width:96%;background:#000000;" align="center" cellpadding="2" cellspacing="1">
<tr>
<td class="header">
</td>
</tr>
<tr>
<td class="subheader">
<table style="border:none;width:100%;margin:0px;" cellspacing="0" cellpadding="0">
<tr>
<td style="text-align:left;">
Welkom terug {$name|ucfirst}.
</td>
<td style="text-align:right;">
<b>Je kan weer stemmen voor 100 kogels!</b>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table style="border:none;width:60%;background:#000000;" align="center" cellpadding="2" cellspacing="1">
<tr>
<td class="textTitle">
Nieuws pagina
</td>
</tr>
{foreach $result as $res}
<tr>
<td class="text">
<span style="font-size:20px;">{$res.title|ucfirst}</span>
<br />
<span style="font-size:10px;">Geschreven op {$res.date|date_format:'%d %B %Y om %H:%S'}</span>
<br />
{$res.message|stripslashes}
</td>
</tr>
{foreachelse}
<tr>
<td class="text">
Er nog geen nieuws.
</td>
</tr>
{/foreach}
<tr>
<td class="text">
Pagina
{foreach $navigation as $i}
{$i--}
<a href="/index.php?={$i}">{($i+1)}</a>
{/foreach}
</td>
</tr>
</table>
<br />
<center>Copyright Messinagame 2011</center>
</td>
<td style="width:14%;vertical-align:top;">
{include file='menu-right.tpl'}
</td>
</tr>
</table>
</body>
</html>
Toon Meer
Er staan 6 nieuwsberichten in de database (dus 6 records)
Ik heb LIMIT op 2 gezet dus hij laat er dan maar 2 zien dat werkt.
Hij zou dus eigenlijk dit moeten weergeven:
Maar hij laat dit zien:
Wat doe ik fout, wie kan me helpen?