dongshi2458
2015-09-06 03:44
浏览 90
已采纳

HTML DateTime.Now减去两小时[关闭]

I'm trying to run conditional formatting inside a insert_mysql.php on data sourced from a MySQL table. Data originates from an Arduino Uno + WiFi Shield that will post a value (any value) and a timestamp each time the button is pressed. A display_mysql.php outputs to HTML so a user can see the result on a web page. For the purposes of this question, the only output the user sees on the page is a single timestamp of the last date/time of a button press, nothing else. I want to format the text according to:
-css_1 if the event occurred less that two hours ago.
-css_2 is the event occurred more than two hours ago.

I tried this but I suspect that there are many flaws. It's only a place to start:

if ($result = mysql_query("SELECT MAX(TimeStamp) AS 'Last Time' FROM {$table}")&lt (%DateTime.Now% - 2)) {
echo '<div class="css_1">';
}
else{
echo '<div class="css_2">';
}

I continue to get a variety of errors related to expected or unexpected characters. This particular code returns: "Parse error: syntax error, unexpected '%', expecting ')' in..."

My question is this... Is there a way to do time calculations within PHP based on MySQL output? The desired outcome is to have a date and time printed on a web page in either green if the event falls within the two hour window, meaning it's a new event, or red if it's older than two hours, meaning it's an old event.

1条回答 默认 最新

相关推荐 更多相似问题