このクエリを 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') にあります。助言がありますか?