-1

我正在开发一个简单的网站,该网站使用 php 中的日期函数来显示当前日期。我熟悉 HTML、CSS 和 Java。根据当前日期,我希望显示不同的信息,例如...

On <?php echo date('F jS'); ?> throughout history, the following events took place:
Event 1 in 1776
Event 2 in 1890
Event 3 in 1999

我有一个信息列表,我只是不确定如何将 2 链接在一起。查看http://www.history.com/this-day-in-history以更好地了解我正在尝试做的事情。

谢谢你的帮助。

4

2 回答 2

4
  1. 创建一个名为events的表
  2. events中,创建行 === id, monthandday, year, event
  3. 使 PHP 选择:

    //connect to db
    $db = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
    
    //get day and month
    $curdate = date("m d");
    
    //select from database of events where matching month and day     
    $statement = $db->prepare("SELECT * FROM events WHERE monthandday = :md ");
    
    $statement->execute(array(':md' => $curdate));
    
    //echo out events that happened throughout history
    echo "On ."date('F jS') ."throughout history, the following events took place:";
    
    while($row = $statement->fetch()){
    
        echo $row['event'];
    }
    
于 2013-01-06T02:37:38.047 回答
1

如果您尝试在 php 中格式化日期,请使用

http://php.net/manual/en/function.date.php

获得年份

回显日期(“Y”,$日期);

于 2013-01-06T02:02:07.600 回答