Jump to content

Mysql string/integer problem [solved]


Ryan_w

Recommended Posts

Hey Guys,

    Need a bit of help with a problem pulling data from a mysql database. I have timestamps stored in an integer field in mysql. I am pulling those rows out in a foreach statement, and I need to run the date function to output that timestamp in a human readable format in a table. When I pull that field with the rest of the row it is entered into the array as a string. I have tried the normal ways (intvar, (int)) to convert this to an integer to be used in the date command and none seem to do so properly. How can I go about converting that string into a proper integer without changing the timestamp?

 

Basic jist of what I am trying to do:

 

 

$sql = ("SELECT * FROM database WHERE field = '" . $variable . "';");
$result = mysql_query($sql);

foreach (mysql_fetch_assoc($result) as $row)
{
      echo(date('format string', $row["timestamp"]));
}

 

Link to comment
https://forums.phpfreaks.com/topic/84875-mysql-stringinteger-problem-solved/
Share on other sites

$row["timestamp"] contains a unix timestamp inserted by another application....but php pulls it as a string into the array instead of an integer....and date() won't have it.

 

 

 

Warning: date() expects parameter 2 to be long, string given in /root/php/test.php on line 19

 

If I echo the entire array it shows the timestamp file....but when I echo($row["timestamp"]; it converts the string into a set of alpha numeric chars and that is what the date function sees.

I still get multiple errors about date wanting a long int....because it is interpreting it as a string

 

I am only a couple months into using PHP....I would love to use an object....but I really don't want to spend 5 hours learning a whole new concept right now to fix this :/

 

There has to be a simple way to either tell it to pull this as an integer like it is stored in the database or to convert it properly I would think.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.