简体   繁体   中英

PHP: using strtotime to convert a MySQL UTC date for pChart use

I've RTM, but I'm really not sure how to use the strtotime function to convert a date from UTC to unix time, because I'm not sure what variables go where. Here's the specific code:

$value = $_POST["Attribute"];
$Customer = $_POST["customer"];
$table = $_POST["table"];
$date = "date";
$myData = new pData();

$myquery = "SELECT `$value`,`$date` FROM `$table` WHERE `Customer` LIKE '$Customer' ORDER BY `date`";
$result = mysql_query($myquery,$connect);
while ($row = mysql_fetch_array($result))
 { $myData->AddPoints($row["$value"],"serie1");
   $date2 = date($date,strtotime($row["date"]));
   $myData->AddPoints($row["$date2"],"date"); }

arrghhh, I can barely even see anymore. I think the problem is the penultimate line, I just don't know what slots in where. The date column in my database is UTC, and then I need to pass that value to pChart using the $mydata->AddPoints function. That works, but the data is messed up.

Can anyone help me?

我想您的strtotime()很好,问题似乎是您使用的是$row["$date2"]但是您将时间戳保存到$date2

Well, this isn't a solution to THE problem, but it is a workaround. I found out I could use "UNIX_TIMESTAMP( $date ) as ut_date" in my select query, and that actually works fine. Looks a lot cleaner too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM