Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Date Column

  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Date Column

    Hello,
    So I want to create a Mysql table on my phpMyadmin with : id, id_member, date, and message
    so can anyone help me to set up the attribute for each column/field?

    Field: ID
    Type: INT
    Length/Values: 11
    Default: None
    Collation:
    Attributes:
    Null: <---- this is a check box
    AUTO_INCREMENT <----check box
    Comment:

    Field: id_member <--- which is registered user of the website
    Type: ?
    Length/Values: ?
    Default: None
    Collation:
    Attributes:
    Null: <---- this is a check box
    AUTO_INCREMENT <--
    Comment:

    Field: date <--- which is the current time and date
    Type: ?
    Length/Values: ?
    Default: None
    Collation:
    Attributes:
    Null: <---- this is a check box
    AUTO_INCREMENT <---- another check box
    Comment:


    Field: message
    Type: ?
    Length/Values: ?
    Default: None
    Collation:
    Attributes:
    Null: <---- this is a check box
    AUTO_INCREMENT <---- another check box
    Comment:

  • #2
    New Coder
    Join Date
    Oct 2011
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I recomend you to do some homework,
    there are lot of information in google,
    this is the first I found:
    http://help.scibit.com/mascon/mascon...eld_Types.html

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    Forget using phpmyadmin to do a field at a time.

    Just do it with a SQL query:
    Code:
    CREATE TABLE nameOfTable (
        id INT AUTO_INCREMENT PRIMARY KEY,
        id_member INT REFERENCES members(id),
        theDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        message TEXT );
    You said
    Field: id_member <--- which is registered user of the website
    so I assumed you meant you have another table (which I assumed is named members) with a column for the id of the member. If the other table and/or field name is not members(id) then change that to match what you are actually using.

    The only way you can have a default value of "current time and date" in MYSQL is the way I showed it there. I urge you *NOT* to name the column just date as that name is a builtin function name in MySQL and can lead to confusion. Just use a simple variation on the name, such as theDate as I showed there.

    Finally, you didn't say how long a message can be, so I used text as the data type, which allows message of virtually any length. If messages can't be more than a few thousand characters, it might (or might not) be worth using a different type.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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