• Login
  • Register
  • Zoek
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Filebase Entry
  • More Options

ICTscripters

Dé plek voor IT

Dé plek voor IT

Login

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Scripting & programmeren
  4. PHP + SQL

Forum

  • Crimora.nl

    Dennii 11 juli 2026 om 13:13
  • RPG game gebouwd met AI

    zwpgangster 9 juli 2026 om 11:25
  • (Verkoop) Criminals

    Syntax 5 juli 2026 om 13:22
  • Het Grote Vibe Code Topic

    Syntax 30 juni 2026 om 11:54
  • Ictscripters Chat

    Jeffrey.Hoekman 26 juni 2026 om 16:21
  • Het oorspronkelijke Criminals Script

    Jeroen.G 24 juni 2026 om 09:21
  • StraatBaas is back, maar hoe?!

    Syntax 17 juni 2026 om 10:28
  • PWYL source gezocht

    Syntax 29 mei 2026 om 14:03

Marktplaats

  • 306 Nieuwe Domeinnamen Juni 2026

    shiga 1 juli 2026 om 13:39
  • 4-letter domein: Togi.nl

    evesi 17 juni 2026 om 17:08
  • 359 Nieuwe Domeinnamen Mei 2026

    shiga 1 juni 2026 om 12:45

Smarty foreach fout

  • Jackie
  • 20 februari 2011 om 03:11
  • Jackie
    Hardstyle
    Berichten
    224
    • 20 februari 2011 om 03:11
    • #1

    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"> 
                            &nbsp;
                        </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:

    PHP
    Pagina 1 2 3

    Maar hij laat dit zien:

    PHP
    Pagina 1 1 2 2 3 3

    Wat doe ik fout, wie kan me helpen?

    Bezig met een zelf gemaakte source, geschreven vanaf 0 natuurlijk!

  • Darsstar
    Vreemd
    Berichten
    1.173
    • 20 februari 2011 om 12:23
    • #2
    PHP
    {foreach $navigation as $i}
                            <a href="/index.php?={($i-1)}">{$i}</a>
    {/foreach}

    Zo misschien?
    Ik weet niet veel van smarty, maar het lijkt me dat {$i--} geprint werd.

    miauw!

  • Jackie
    Hardstyle
    Berichten
    224
    • 20 februari 2011 om 13:01
    • #3

    Dankjewel hij werkt nou :)

    Bedankt!

    :slotje:

    Bezig met een zelf gemaakte source, geschreven vanaf 0 natuurlijk!

Participate now!

Heb je nog geen account? Registreer je nu en word deel van onze community!

Maak een account aan Login

ICT Nieuws

  • Quanscient ontvangt €10M om AI- en kwantum-native hardware engineering te bevorderen - Tech.eu

    ICTscripters 27 mei 2026 om 12:03
  • Datalek bij leverancier Canvas - Universiteit van Amsterdam

    ICTscripters 10 mei 2026 om 12:03
  • Data privacy in 2026: Hoe de naleving van GDPR verandert

    ICTscripters 8 mei 2026 om 12:16

Blogs

  • Functioneel ontwerp

    Dees 28 december 2014 om 12:38
  • Access Control List implementatie in PHP/MySQL - deel 1/2

    FangorN 28 december 2018 om 12:35
  • Access Control List implementatie in PHP/MySQL - deel 2/2

    FangorN 29 december 2018 om 12:37
  1. Marktplaats
  2. Design
  3. Voorwaarden
  4. Ons team
  5. Leden
  6. Geschiedenis
  7. Regels
  8. Links
  9. Privacy Policy
ICTscripters ©2005 - 2026 , goedkope hosting door DiMoWeb.com, BE0558.915.582
Sponsors: Beste kattenhotel provincie Antwerpen | Beste Zetes eid kaartlezer webshop
Style: Nexus by cls-design
Stylename
Nexus
Manufacturer
cls-design
Licence
Commercial styles
Help
Supportforum
Visit cls-design