SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    create unique dateAdded for db

    Hi Guys

    I have a form that uploads multiple images at once. I have a Select query that displays this images based on the date added. The format is this YYYY-MM-DD HH:MM:SS . The only problem is that sometimes the images get uploaded at the same second. As you would have guessed it this breaks. I also found out that MySQL doesn't store microseconds so I need a way to do this. I thought about Timestamps don't know how to generate it correctly in the PHP code before INSERT. any suggestions?

    I'm trying to get it inserted into the db but I kept getting odd results.

    Like the number 1230581547.2404211 gets inserted into the db as 1.23058e+009 with the float data type. Do you know what the problem is?

    What data type did I need to use for this to work and micro time work for this.

    Here is my good to generate the microtime

    PHP Code:
      function mtime()
    {
        
    preg_match('/^0\.(\d+) (\d+)$/',microtime(),$out);
        return 
    $out[2].'.'.$out[1];
    }

        
    $uniqueTime mtime();

        
    $uniqueTime number_format($uniqueTime,7,'.'''); 

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What "breaks"? Why does the time need to be unique?

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Time to refactor me thinks!

    Just create another table with an auto increment ID, each entry will therefore be unique regardless of upload 'time'.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Addict lespaulsf's Avatar
    Join Date
    Dec 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a complicated query that uses the time uploaded to return certain sets of images. simply auto increment ID is not nearly enough simply because of the way the photo gallery works. Needless to say I figured it out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •