PHP / MySQL查询 - 如果当前时间/日期在计划中 [英] PHP / MySQL query - if current time/date is in schedule

查看:163
本文介绍了PHP / MySQL查询 - 如果当前时间/日期在计划中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图开发一个简单的php基于日程表...

I'm trying to develop a simple php based schedule ...

这是我的数据库表:

This is my database table:

假设当前时间/日期为:<$​​ c $ c> 2012-03-21 02:00:00

Let's say that current time/date is: 2012-03-21 02:00:00

PHP脚本应该回应: 会议2

PHP script should echo: Meeting 2

我有一部分脚本,但不知道该怎么做

I have a part of the script, but no idea what to do next

<?php
$con = mysql_connect("localhost","root","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("schedule", $con);

$current_time = date("Y-m-d H:i:s");

$result = mysql_query("SELECT * FROM events");

while($row = mysql_fetch_array($result)){

  echo $row['Subject'];
}
mysql_close($con);
?>

如何筛选查询,mach当前时间和预定主题?谢谢!

(如果 current_time 介于 StartTime EndTime - echo it's Subject

(if current_time is between StartTime and EndTime - echo it's Subject)

推荐答案

尝试此查询

SELECT * FROM events WHERE NOW() BETWEEN StartTime AND EndTime

EDIT
测试并删除无用限制和排序

EDIT tested and deleted useless limit and order by

这篇关于PHP / MySQL查询 - 如果当前时间/日期在计划中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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