SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    May 2004
    Location
    London
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to add 3 variables to a table field - Setting a Delivery year, month, day

    How can I set the field "deliverydate" with the variables year, month and day?

    Should I have one field for each variable?

    Am I doing this right?

    PHP Code:
    $query "INSERT INTO orders
     SET 

    deliverydate = '
    $eyear$emonth$eday'
    , "


  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    please show your entire CREATE TABLE statement
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    May 2004
    Location
    London
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still building everything..

    PHP Code:

    CREATE TABLE 
    `orders` (
    `
    idint(4NOT NULL auto_increment,
    `
    productvarchar(50NOT NULL default '',
    deliverydate '$eyear, $emonth, $eday"'
    KEY `id` (`id`)
    ) ; 

  4. #4
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you mean you want to insert a date into the field "deliverydate", then yuou would do something like this:

    PHP Code:
    $date date("j").'/'.date("m").'/'.date("Y"); // d/mm/yyyy

    $query "INSERT INTO orders (deliverydate) VALUES '".$date."'";
    $result mysql_query($query)or die(mysql_error()); 
    Or if you have the year month and day in seperate variables, then join the variables, and then do the insert.

    PHP Code:
    $thedate $eyear.'/'.$emonth.'/'.$eday
    I think that's what you mean anyway. Of course if your deliverydate field is in the date format, then this wouldn't work.
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  5. #5
    SitePoint Zealot
    Join Date
    May 2004
    Location
    London
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, F4nat1c, that works beautifully!

  6. #6
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Maria Sohas
    Thank you, F4nat1c, that works beautifully!
    No problem, glad to have helped. I don't really see why this post got moved to the MySQL forum anyway.
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Maria Sohas
    CREATE TABLE `orders` (
    `id` int(4) NOT NULL auto_increment,
    `product` varchar(50) NOT NULL default '',
    deliverydate = '$eyear, $emonth, $eday"'
    KEY `id` (`id`)
    )
    bold part is not right, it should say
    Code:
    deliverydate DATE
    when you go to insert values into this column, make sure the values are specified in standard format

    how you produce those values is of course a php issue, not a mysql issue

    however, the values must be specified in year-month-day sequence

    the best way is to use standard 'yyyy-mm-dd' date strings, e.g. '2006-03-09' (note the single quotes and dashes)

    mysql also allows you to submit date values as integers, e.g. 20060309

    however, if you write your php code to generate integers, you won't be able to port your app to any other database, because they all use 'yyyy-mm-dd'
    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
  •