douyunjiaok300404 2019-06-07 07:26
浏览 63
已采纳

在为echo命令调用列时打印出错误的日期

I am trying to show only the year from a date field for my loop, but when I am trying to call it, it shows me the wrong year. It shows 1970 for all the results.

I'm new to wordpress and php and don't know how to exactly show my results. Is my query for $mydate incorrect or is it a coding error when being echoed?

<table class="teachpress_publication_list">

      <?php

        global $wpdb;

    // QUERY HERE TO COUNT TOTAL RECORDS FOR PAGINATION 
    $total = $wpdb->get_var("SELECT COUNT(*) FROM (SELECT * FROM wpfs_teachpress_pub LIMIT 0,650) AS a");
    $post_per_page = 10;
    $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
    $offset = ( $page * $post_per_page ) - $post_per_page;
    $result = $wpdb->get_results( "SELECT * FROM wpfs_teachpress_pub ORDER BY date DESC LIMIT $post_per_page OFFSET $offset");
    $mydate = $wpdb->get_results( "SELECT date FROM wpfs_teachpress_pub" );
    foreach ( $result as $print )   { ?>

          <tr class="tp_publication">

                  <td class="tp_pub_info"> <p class="tp_pub_author"> <?php echo $print->editor; ?><br/>
                  <span class="tp_pub_title"> <?php echo $print->title; ?></span><br/><?php echo $print->journal; ?>&nbsp;<span class="dd">Year Published:<?php echo date("Y", strtotime($mydate)); ?></span> </p>

          </tr>

            <?php }
          ?>
</table>

I expect the output to show the correct year in the date column of MySql db instead of always 1970.

Any help would be greatly appreciated.

  • 写回答

2条回答 默认 最新

  • donglu6805 2019-06-10 08:52
    关注

    Finally figured it out just used print function along with date() function

    <?php echo date("Y", strtotime($print->date)); ?>
    

    Now am able to display only year from my db column.

    Thanks a lot all for the support!

    Hariharan

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理