0

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?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Soop
  • 345
  • 5
  • 19
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. – Kermit Mar 20 '13 at 15:35
  • Not an help for your immediate problem but you are querying with raw $_POST variables which will end up with sql injection security vulnerabilities. – Volkan Mar 20 '13 at 15:41

2 Answers2

1

I guess your strtotime() is fine, the problem seems to be that you're using $row["$date2"] but you saved the timestamp into $date2

ulentini
  • 2,413
  • 1
  • 14
  • 26
  • Ok, I tried saving the datestamp into `$row["$date"]`, and it's passing the value on, but it's still mishandling it, which looks like it's not converted correctly :/ – Soop Mar 20 '13 at 15:52
  • Well, your code is a bit confusing, you call your field `$date` in your query, but then you pass `$row['date']` to `strtotime()`. Maybe you need to refactor a bit your code :P – ulentini Mar 20 '13 at 15:56
  • Yeah, that was probably the result of my scattergun approach. I'll hit my head against the brick wall a few more times and see what I come up with! – Soop Mar 20 '13 at 16:14
0

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.

Soop
  • 345
  • 5
  • 19