PHP / MySQL从表中选择数据并以不同的形式显示结果 [英] PHP /MySQL Select data from table and display result in different form

查看:94
本文介绍了PHP / MySQL从表中选择数据并以不同的形式显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下表中,名为lecture_table



---------------------- -------

|一天|开始|结束|

| ------------- + ------ + ------ |

|星期天| 8.5 | 10.5 |

-----------------------------

i试试



i有一个开始时间的网页搜索页面,我想键入讲座时间,如08:30 AM而不是8.5,然后将此值转换为8.5,如上表所示。



结果我希望在开始时间显示为08:30 AM,在结束时间显示为10.30 AM。所以我应该使用什么样的查询来获得这样的结果



--------------------- ---------------

|一天|开始|结束|

| ------------- + -------- + ----------- |

|星期天| 08:30 AM |上午10:30 |

------------------------------------

in the below table which is named as lecture_table

-----------------------------
| day | start | end |
|-------------+------+------|
| Sunday | 8.5 | 10.5 |
-----------------------------
i try to

i have a web search page of start time and i want to type lecture time such as"08:30 AM" instead of 8.5 then this value converted to 8.5 like in the table above.

the result i want to be shown like "08:30 AM" for start time and "10.30 AM" for end time. so what a query should i use to get a result like this

------------------------------------
| day | start | end |
|-------------+--------+-----------|
| Sunday | 08:30 AM| 10:30 AM |
------------------------------------

推荐答案

将start和end的数据类型更改为TIME。现在,当您以HH:MM:SS格式插入数据库插入时。当您还检索时,您将获得相同的格式。如果你想以其他方式格式化它,你可以使用php。
Change the datatype of start and end to TIME. Now, while you insert into the database insert in the format HH:MM:SS. While you retrieve also, you will get in the same format. If you want to format it in someother way, you can do so using php.


这篇关于PHP / MySQL从表中选择数据并以不同的形式显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆