2
<?php
    //run a select query to my latest 1 item
    include "storescripts/connect_to_mysql.php";
    // This block grabs the whole list for viewing
$dynamicList= "";
$sql = mysql_query("SELECT * FROM blog");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
             $title = $row["title"];
             $author = $row["author"];
             $category = $row["category"];
             $article = $row["article"];
            // $postdate = strftime("%b %d, %Y", strtotime($row["postdate"]));
              $postdate = $row["postdate"];
             //Seperate so it's easier to see what i'm working with here.
             $short = substr(strip_tags($article), 0, 400);

             $dynamicList .= '<ul>
<li>
<div class="wrapFirstRowBlog">
    <div class="postDate">'.$postdate.'</div>
    <div class="nextToDate">
    <div class="blogTitle"><h3><a href="blog.php?id='.$id.'">'.$title.'</a></h3></div>
    <div class="author">written by '.$author.' for the '.$category.' section.</div>
    <div class="socialNetwork"></div>
    </div>
</div>
<div class="blogPreview">
<img class="blogLeft" src="../blog_images/'.$id.'.jpg" width="150" height"150" alt="'.$title.'"/>'.$short.'...<a href="http://www.moniquetrinidadjewelry.com/images/new-images/read-more.png"><img src="http://www.moniquetrinidadjewelry.com/images/new-images/read-more.png" alt="read more of this post" /></a>
</div>
</li>
</ul>';
    }
} else {
    $dynamicList = 'Nothing posted yet...check back soon!';
}
mysql_close();
?>

我已经尝试了许多在这里到处搜索的组合,我可以从我的脚本开始做我想做的事情。我正在尝试将日期转换为仅显示日期。我的mysql阅读是

2013-06-03 00:18:32 

我想简单地把它剪掉,只显示日期而不是时间。当它在我的脚本中时,我似乎无法弄清楚如何去做。我试过了

$postdate = strftime("%b %d, %Y", strtotime($row["postdate"]));

这是该行的包含,无法弄清楚。我应该在什么时候输出这些更改以及任何关于为什么的参考将不胜感激。

4

1 回答 1

2

我认为你可以使用date功能

$postdate = date("m d, Y", strtotime($row["postdate"]));

这将在您的变量中存储您$postdate的日期

06 03, 2013

现场演示

于 2013-06-03T21:30:16.183 回答