php - 如何使用上一个和下一个按钮在表格中显示周

标签 php mysql

我得到了下面的代码来获取当前星期的日期并显示在 html 表格上:

<table>
<tr>
<td><a href="#"> << </a> </td>
<td></td>
<td><a href="#"> >> </a> </td>
</tr>
<tr>
<?php 
$ts = date(strtotime('last sunday'));
$dow = date('w' , $ts);
$offset = $dow - 1 ;

    if($offset < 0 ){
    $offset = 0 ;
        }

$ts = $ts - $offset * 86400;
for ($x=0 ; $x<7 ; $x++,$ts += 86400) {
echo '<td>' . date("m-d-Y", $ts) . '</td>' ;
    }
?>
</tr>
</table>

从“星期日”开始以及当前星期的日期如何,工作正常。 但我使用“下一个”和“上一个”按钮/链接来显示下周和上周。

但我无法显示上周的详细信息和下周的日期。此外,一旦检索到上一周或下一周的日期,它应该继续继续,没有任何错误 X 周。

我如何使用 PHP/mysql 来做到这一点。 谁能帮我解决这个问题。

谢谢, 亚山。

最佳答案

你可以试试这个。某种分页:

<?php

    (int)$currentpage = (!empty($_GET["currentpage"]))?$_GET["currentpage"]:0;
    (int)$nextpage = $currentpage + 1;
    (int)$prevpage = $currentpage - 1;

?>

<table>
    <tr>
        <td><a href="<?php echo "{$_SERVER['PHP_SELF']}?currentpage=$prevpage"; ?>"> << </a> </td>
        <td></td>
        <td><a href="<?php echo "{$_SERVER['PHP_SELF']}?currentpage=$nextpage"; ?>"> >> </a> </td>
    </tr>
    <tr>
        <?php
            $ts = date(strtotime('last sunday'));
            $ts += $currentpage * 86400 * 7;
            $dow = date('w' , $ts);
            $offset = $dow;

            $ts = $ts - $offset * 86400;
            for ($x=0 ; $x<7 ; $x++,$ts += 86400) {
                echo '<td>' . date("m-d-Y", $ts) . '</td>' ;
            }
        ?>
    </tr>
</table>

关于php - 如何使用上一个和下一个按钮在表格中显示周,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37692179/

相关文章:

php - 统计同一个表中的后代数量

php - 如何使用 PHP 检查页面 url 中是否包含 www?

MySQL - 获取计数的最大值

php - 让用户等待再次尝试连接 - mysqli php

php - MySQL 中的日期排序

php - 使用 Selenium 通过测试帐户登录 Facebook

PHP RegEx 允许 mailto : http://and tel: hyperlinks

php - 如何使用 PHP 为 JSON 创建一个数组?

php - 使用自动增量值将一张表复制到mysql中的新表

mysql - 使用 SELF JOIN 的简单 MySQL 查询