与php建立链接?

时间:2012-08-24 09:51:13

标签: php date for-loop

我希望有这种链接

<li><a href="arhiva?year=2009">Kamp 2009/10</a></li>
<li><a href="arhiva?year=2007">Kamp 2007/08</a></li>

但明年我想自动添加新的链接

<li><a href="arhiva?year=2011">Kamp 2011/12</a></li>

如何使用PHP for循环执行此操作,我有变量$today = date("Y");

2 个答案:

答案 0 :(得分:1)

你走了:

<?php

    $currentYear = date("Y"); // same as your $today variable

    for ($i = 2007; $i < $currentYear; $i++) {
        $nextYear = date("y",mktime(0, 0, 0, date("m"),   date("d"),   $i+1));
        echo "<li><a href=\"arhiva?year=$i\">Kamp $i/$nextYear</a></li>";
    }

答案 1 :(得分:0)

我错过了什么吗?

<?php
    for ($i = 2007; $i <= $today; $i++) {
        echo "<li><a href=\"arhiva?year=$i\">Kamp $i/08</a></li>";
    }
?>