[英]Select id based on todays date
I got a table named stats_eu
that stores id, acc_name
and date
. 我得到了一个名为
stats_eu
的表,该表存储id, acc_name
和date
。 I would like to select id
based on acc_name
and date
. 我想根据
acc_name
和date
选择id
。 The date
in the database is stored like this: 2015-05-16 13:35:19 (datetime) 数据库中的
date
是这样存储的:2015-05-16 13:35:19(datetime)
This is what I have tried that didn't work: 这是我尝试过的无效的方法:
$result = mysql_query("SELECT `id` FROM `stats_eu` WHERE `acc_name`='".$name."' AND `date`='".date('Y-m-d')."'");
$row = mysql_fetch_array($result);
echo "name: " . $name . "<br />";
echo "id: " . $row['id'] . "<br />";
That code just prints the name
but not the id
. 该代码仅显示
name
,而不显示id
。 Could someone please point our my error? 有人可以指出我们的错误吗?
MySql Date()
函数将字符串或日期时间转换为日期。只需使用此查询
$result = mysql_query("SELECT `id` FROM `stats_eu` WHERE `acc_name`='".$name."' AND Date(`date`)=Date(NOW())" );
Try this.... 尝试这个....
$result = mysql_query("SELECT `id` FROM `stats_eu` WHERE `acc_name`='".$name."' AND `date` LIKE '".date('Y-m-d')."%'");
I added LIKE operator in your query... 我在您的查询中添加了LIKE运算符...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.