数据库条目
In Database Row Day = {Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}
PHP代码
$today = date('l');
$result = mysql_query("SELECT * FROM alert WHERE Day = '$today' ");
我想知道如何根据今天的情况从MySQL数据库中获取数据?
答案 0 :(得分:0)
试试这个
$result = mysql_query("SELECT * FROM alert WHERE FORMAT(Now(),'YYYY-MM-DD') AS PerDate = FORMAT(your_col,'YYYY-MM-DD') ");
答案 1 :(得分:0)
试
mysql_query("SELECT * FROM alert WHERE Day = DAYNAME('2008-05-15')");
了解更多信息http://www.w3resource.com/mysql/date-and-time-functions/mysql-dayname-function.php
答案 2 :(得分:0)
试试这个 -
<?php
$jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$today=jddayofweek($jd,1);
$result = mysql_query("SELECT * FROM alert WHERE Day = '$today' ");
?>
答案 3 :(得分:0)
尝试
<?php
$today = date('l'); // get day of week today;(its 'L' in lowercase)
$result = mysql_query("SELECT * FROM alert WHERE Day = '{$today}' ");
?>