dongtao9095 2014-11-26 22:17
浏览 30
已采纳

订单结果与数据库中的日期,不显示它应该是

Okay, i have search everywhere on the web for this and i couldn't find it so i ask my problem here.

First i show you my code:

if ($result = $mysqli->query("SELECT * FROM jarig
                              WHERE maand = 'April'
                              ORDER BY datum"))
                         {
                           if ($result->num_rows > 0)
                         {                                                                               
                           while ($row = $result->fetch_object()){
                           $date = new DateTime($row->datum);                                                   
                           echo "'" . $date->format('d') . "  " . $row->naam;
                           echo "<br />";                                               
                         }
                         }
                         }

My Problem:

As you see, i have a row that contains the names of the months of the year so i do not need to make more tables and easy to display because i can order it by months seperate. Also i have a row with the birthdates.

The birthdates (named as DATUM on the table) are in 'DATE' type on my table (i hope i say it right).

example The DATES in that row are as follow:

----------
  DATUM
----------
1991-04-07
1978-04-12
2001-04-24

They are random filled in and that is with all the dates i stored in my database with birthdays.

The output as i liked to see on my website is kinda differently then how i wanted to have. The results are displayed only as days because it goes directly in the tablecell where they belong in html:

Calendar Month: April
'12 Jan
'07 kees
'24 Frans

My Question:

This happen on all the dates i have but i like to see that they are displayed from the first date in the month to the last date on the month in the right order and not randomly. Like i showed you above. Like to see them in this order, from lowest to highest numbers (07,12,24).

How do i fix this issue?

  • 写回答

1条回答 默认 最新

  • douwa0280 2014-11-26 22:23
    关注

    Maybe try to change your query:

    SELECT jarig.*, DATE_FORMAT(jarig.datum, '%d') AS day FROM jarig
    WHERE maand = 'April'
    ORDER BY day
    

    What you really need is just the day of the date, not the date in itself. So you can order by the day instead of the date.

    Then in your php, just use the day column:

    echo "'" . $row->day . "&nbsp;&nbsp;" . $row->naam;
    echo "<br />";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。