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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.