我正在尝试将此查询执行到我的 php 文件中,但不返回任何结果(无错误)
$day = $_GET["day"];
$query_string = "SELECT * FROM $tablename WHERE TIMESTAMP('date','time') BETWEEN '$day 07:01:00' AND DATE_ADD('$day',INTERVAL '1 7' DAY_HOUR) ORDER BY kod";
display_db_query($query_string, $connection, $header_bool, $table_params);
//date format: yyyy-mm-dd
//time format: hh:mm:ss
任何人都可以帮忙吗?$query_string 有什么问题吗?
这是 display_db_query 代码:
function display_db_query($query_string, $connection, $header_bool, $table_params) {
// perform the database query
$result_id = mysql_query($query_string, $connection)
or die("display_db_query:" . mysql_error());
// find out the number of columns in result
$column_count = mysql_num_fields($result_id)
or die("display_db_query:" . mysql_error());
// Here the table attributes from the $table_params variable are added
print("<TABLE $table_params >\n");
// optionally print a bold header at top of table
if($header_bool) {
print("<TR>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
print("<TH>$field_name</TH>");
}
print("</TR>\n");
}
// print the body of the table
while($row = mysql_fetch_row($result_id)) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
print("<TD>$row[$column_num]</TD>\n");
}
print("</TR>\n");
}
print("</TABLE>\n");
}
当我手动执行查询时:
SELECT * FROM stats_temp WHERE TIMESTAMP('date','time') BETWEEN '2013-04-28 07:01:00' AND DATE_ADD('2013-04-28 00:00:00',INTERVAL '1 7' DAY_HOUR) ORDER BY kod
它返回 0 个结果。
当我手动执行没有 DATE_ADD 但手动计算的查询时:
SELECT * FROM stats_temp WHERE TIMESTAMP('date','time') BETWEEN '2013-04-28 07:01:00' AND '2013-04-29 07:00:00' ORDER BY kod
它也返回 0 个结果,这是不可能的,因为有符合此标准的数据。
数据格式正确,所以问题出在TIMESTAMP('date','time')。有什么建议么?