SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing numerical data as a timestamp?

    Hi Everyone,

    I'm trying to figure out how to properly configure my mysql database to store numbers as a timestamp. I don't believe this is the correct way to do so. I tried changing the TYPE to VARCHAR but I get a mysql error. The below URL is where I want my user to input information.

    Column
    TYPE | timestamp
    Default | CURRENT_TIMESTAMP
    Collation
    Attributes | ON UPDATE CURRENT_TIMESTAM
    Null
    Auto_Increment
    Comments

    http://whatsmyowncarworth.com/auto-m.../math/math.php

    >>>>>>>>>>

    This is what I'm trying to do.

    At the below URL their are two users. They each have a favorite number.

    http://www.whatsmyowncarworth.com/au...ember-info.php
    hockeyman = 2
    coolguy = 3

    If hockeyman changes his number to 8
    and
    coolguy changes his number is 12

    Using a timestamp what's the best way to store the old numbers of 2/3? while keeping the new numbers of 8/12.

    Thanks everyone!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by scm22ri View Post
    ...to store numbers as a timestamp.
    you lost me right here

    why would you want to store a number as a timestamp?

    i went to your math.php page and it made no sense whatsoever

    also, this --
    what's the best way to store the old numbers of 2/3? while keeping the new numbers of 8/12
    did not make sense either

    i'm pretty good with mysql, but in this case, the requirements have got me completely stymied
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi R937,

    My mistake. I gave the wrong URL and worded my question improperly. This is what I meant.

    This is what I'm attempting to do. I want to store numbers for each user in a mysql table.

    Let's say for example user "bob jones" inputs his favorite number of 2 @ 2012-08-21 18:24:45. Then one day later he then changes his fav number to 5. How would I store/keep his first number of 2 and also 5 in a mysql table?

    http://whatsmyowncarworth.com/auto-m...stamp-data.php

    "Bob Jones" inputs his info. at this below URL
    http://whatsmyowncarworth.com/auto-m.../timestamp.php

    Thanks!

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by scm22ri View Post
    Let's say for example user "bob jones" inputs his favorite number of 2 @ 2012-08-21 18:24:45. Then one day later he then changes his fav number to 5. How would I store/keep his first number of 2 and also 5 in a mysql table?
    by simply inserting each of his choices in the table, along with the timestamp of when he chose it

    a 3-column table will do it -- userid, chosen_number, datetime_chosen

    if you want to see his current choice, just run a query with ORDER BY date_chosen DESC LIMIT 1

    gangnam style
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi r937,

    Thanks for the reply. I have a few questions.

    In your process wouldn't I need to create a new table every-time a user inputs a new favorite number?

    The reason why I ask is because what if user "bob jones" wants to add 15, 25 or 125 new favorite numbers. Wouldn't each new favorite number need a new table?

    Thanks!

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    No, you create a new row in the table.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by logic_earth View Post
    No, you create a new row in the table.
    more specifically, using an INSERT statement
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •