SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying date of an archive

    Hi I am trying to display the date of a day.php. When I click on the archive date I want it to show the date in a readable format.

    Here is my code:

    Code:
     
    <?php require_once('Connections/connNickToye.php'); ?>
    <?php
    $year_rsArticlesByDate = "-1";
    if (isset( GET['y'])) {
    $year_rsArticlesByDate = (get_magic_quotes_gpc()) ? GET['y'] : addslashes( GET['y']);
    }
    $month_rsArticlesByDate = "-1";
    if (isset( GET['m'])) {
    $month_rsArticlesByDate = (get_magic_quotes_gpc()) ? GET['m'] : addslashes( GET['m']);
    }
    $day_rsArticlesByDate = "-1";
    if (isset( GET['d'])) {
    $day_rsArticlesByDate = (get_magic_quotes_gpc()) ? GET['d'] : addslashes( GET['d']);
    }
    mysql_select_db($database_connNickToye, $connNickToye);
    $query_rsArticlesByDate = sprintf("SELECT * FROM articles WHERE date_format(pub_date, '%%Y-%%c-%%e')='%s-%s-%s' ORDER BY pub_date DESC", $year_rsArticlesByDate,$month_rsArticlesByDate,$day_rsArticlesByDate);
    $rsArticlesByDate = mysql_query($query_rsArticlesByDate, $connNickToye) or die(mysql_error());
    $row_rsArticlesByDate = mysql_fetch_assoc($rsArticlesByDate);
    $totalRows_rsArticlesByDate = mysql_num_rows($rsArticlesByDate);
    mysql_select_db($database_connNickToye, $connNickToye);
    $query_rsArticleDates = "SELECT date_format(pub_date, '%Y-%c-%e') as ArticleDate FROM articles";
    $rsArticleDates = mysql_query($query_rsArticleDates, $connNickToye) or die(mysql_error());
    $row_rsArticleDates = mysql_fetch_assoc($rsArticleDates);
    $totalRows_rsArticleDates = mysql_num_rows($rsArticleDates);
    $maxRows_rsArticles = 5;
    $pageNum_rsArticles = 0;
    if (isset( GET['pageNum_rsArticles'])) {
    $pageNum_rsArticles = GET['pageNum_rsArticles'];
    }
    $startRow_rsArticles = $pageNum_rsArticles * $maxRows_rsArticles;
    mysql_select_db($database_connNickToye, $connNickToye);
    $query_rsArticles = "SELECT * FROM articles ORDER BY `pub_date` ASC";
    $query_limit_rsArticles = sprintf("%s LIMIT %d, %d", $query_rsArticles, $startRow_rsArticles, $maxRows_rsArticles);
    $rsArticles = mysql_query($query_limit_rsArticles, $connNickToye) or die(mysql_error());
    $row_rsArticles = mysql_fetch_assoc($rsArticles);
    if (isset( GET['totalRows_rsArticles'])) {
    $totalRows_rsArticles = GET['totalRows_rsArticles'];
    } else {
    $all_rsArticles = mysql_query($query_rsArticles);
    $totalRows_rsArticles = mysql_num_rows($all_rsArticles);
    }
    $totalPages_rsArticles = ceil($totalRows_rsArticles/$maxRows_rsArticles)-1;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main.dwt.php" codeOutsideHTMLIsLocked="false" -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Archive</title>
    <!-- InstanceEndEditable --><link href="css/myStyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    <!--
    function getWindowHeight() {
    var windowHeight = 0;
    if (typeof(window.innerHeight) == 'number') {
    windowHeight = window.innerHeight;
    }
    else {
    if (document.documentElement && document.documentElement.clientHeight) {
    windowHeight = document.documentElement.clientHeight;
    }
    else {
    if (document.body && document.body.clientHeight) {
    windowHeight = document.body.clientHeight;
    }
    }
    }
    return windowHeight;
    }
    function setFooter() {
    if (document.getElementById) {
    var windowHeight = getWindowHeight();
    if (windowHeight > 0) {
    var contentHeight = document.getElementById('content').offsetHeight;
    var footerElement = document.getElementById('footer');
    var footerHeight = footerElement.offsetHeight;
    if (windowHeight - (contentHeight + footerHeight) >= 0) {
    footerElement.style.position = 'relative';
    footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
    }
    else {
    footerElement.style.position = 'static';
    }
    }
    }
    }
    window.onload = function() {
    setFooter();
    }
    window.onresize = function() {
    setFooter();
    }
    //-->
    </script>
    <style type="text/css">
    <!--
    .style2 {font-size: 10px}
    -->
    </style>
    </head>
    <body>
    <div id="container">
    <div id="header"></div>
    <!-- InstanceBeginEditable name="nav" -->
    <div id="nav">
    <li><a href="index.php">HOME </a></li>
    <li><a href="about.php">ABOUT</a></li>
    <li><a href="blog.php">BLOG</a></li>
    <li><a href="work.php">WORK</a></li>
    <li><a href="contact.php">CONTRACT ME</a></li>
    <li><a href="admin/adminIndex.php">ADMIN</a></li>
    </div>
    <!-- InstanceEndEditable -->
    <div id="content"><!-- InstanceBeginEditable name="main" --><p>&nbsp;</p>
     
    <table border="0" cellpadding="0" cellspacing="2">
    <tr>
    <td class="title"><?php echo $row_rsArticlesByDate['pub_date']; ?></td>
    </tr>
    <?php do { ?>
    <tr>
    <td><?php echo $row_rsArticlesByDate['title']; ?></td>
    </tr>
    <?php } while ($row_rsArticlesByDate = mysql_fetch_assoc($rsArticlesByDate)); ?>
    </table>
    <!-- InstanceEndEditable --></div>
    <div id="sidebar">
    <!-- InstanceBeginEditable name="sidebar" --><span class="sidebarHeader">Recent Articles </span>
    <ul>
    <?php do { ?>
    <li><a href="viewArticle.php?article_id=<?php echo $row_rsArticles['article_id']; ?>"><?php echo $row_rsArticles['title']; ?></a></li>
    <?php } while ($row_rsArticles = mysql_fetch_assoc($rsArticles)); ?>
    </ul>
    </p>
    <p class="sidebarHeader">Archive</p>
    <?php 
    function build_calendar($month,$year,$day) {
    /* Declaring the variables */
    $daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
    $firstDayOfMonth = mktime(0,0,0,$month,1,$year);
    $noDays = date('t',$firstDayOfMonth);
    $dateComponents = getdate($firstDayOfMonth);
    $dayOfWeek = $dateComponents['wday'];
    $monthName = date('F',mktime(0,0,0,$month,1,$year));
     
    global GET;
    global $rsArticleDates;
     
    if (mysql_num_rows($rsArticleDates) > 0){
    mysql_data_seek($rsArticleDates,0);
    while($row_rsArticleDates = mysql_fetch_assoc($rsArticleDates)){
    $dates[] = $row_rsArticleDates['ArticleDate'];
    }
    }
     
    /* Computing the previous month. */
    if($month == 1) {
    $mn=12;
    $yn=$year-1;
    } else {
    $mn=$month-1;
    $yn=$year;
    }
     
    /* Computing the next month. */
    if($month == 12) {
    $mn2=1;
    $yn2=$year+1;
    } else {
    $mn2=$month+1;
    $yn2=$year;
    }
     
    /* Calendar header: next and previous month links */
    $calendar = "<table>";
    $calendar .= "<tr><td><a href=day.php?m=$mn&y=$yn&d=$day>&lt;</a></td>";
    $calendar .="<td colspan=5 align=center>$monthName, $year</td>";
    $calendar .="<td><a href=day.php?m=$mn2&y=$yn2&d=$day>&gt;</a></td></tr>";
    $calendar .="<tr>"; 
     
    /* Calendar header: Display the days of the week */
    foreach($daysOfWeek as $day) { 
    $calendar .= "<td>$day</td>"; 
    } 
    $calendar .= "</tr>"; 
    $calendar .= "<tr>"; 
    $currentDay = 1;
     
    /* Fill in the beginning of the calendar body */ 
    if ($dayOfWeek > 0) { 
    $calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>"; 
    } 
     
    /* Generate the calendar body */ 
    while ($currentDay <= $noDays) { 
    if ($dayOfWeek == 7) { 
    $dayOfWeek = 0; 
    $calendar .= "</tr><tr>"; 
    } 
    $date = $year."-".$month."-".$currentDay;
    if (in_array($date,$dates)) { 
    $calendar .= "<td><a href='day.php?m=$month&y=$year&d=$currentDay'>$currentDay</a></td>"; 
    } else {
    $calendar .= "<td>$currentDay</td>";
    }
    $currentDay++; 
    $dayOfWeek++; 
    } 
    /* Filling in the end of the calendar body */
    if ($dayOfWeek != 7) { 
    $remainingDays = 7 - $dayOfWeek; 
    $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>"; 
    } 
     
    $calendar .= "</table>"; 
    return $calendar;
    } 
    if (isset( GET['m']) && isset( GET['y']) && isset( GET['d'])){ 
    $month = GET['m'];
    $year = GET['y'];
    $day = GET['d'];
    } else {
    $dateComponents = getdate();
    $month = $dateComponents['mon'];
    $year = $dateComponents['year'];
    $day = $dateComponents['mday'];
    }
    echo build_calendar($month,$year,$day); 
    ?>
    <!-- InstanceEndEditable --></div>
    <div id="footer"><span class="style2">
    Powered By Dreamweaver MX 2004, MySQL and PHP. 
    Copyright Nick Toye 2004</span></div>
    </div>
    </body><!-- InstanceEnd --></html>
    <?php
    mysql_free_result($rsArticlesByDate);
    mysql_free_result($rsArticleDates);
    mysql_free_result($rsArticles);
    ?>
    This is what I am getting at the moment when I display the date:

    20041117155450

    Many thanks in advance.

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you can use :

    PHP Code:

    date
    ("d, F, Y"); 
    check out www.php.net/date

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So where do I put this code

    PHP Code:
    date("d, F, Y"); 

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Chenk the php manula date and time functions, I'm sure there is a way to display just the year, month and date.

    What is the format of the field in your database table?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The format of the field is a timestamp

  6. #6
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fixed it, thank christ, wasn't that difficult, a nights sleep, an actimel yoghurt and i'm ready for anything.

  7. #7
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good Going Nick!

  8. #8
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers, it was quite simple in the end, its weird how things look different after you go and play commando's for a day and then come back.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •