543 users online (0 members and 543 guests)  


  Results 1 to 4 of 4

Related

  1. Replies: 1
  2. Populate fields by javascript using MYSQL    Forum: Javascript Forum
    Replies: 0
  3. The sum of two fields    Forum: Website Scripts Forum
    Replies: 4
  4. The sum of two fields    Forum: HTML Forum
    Replies: 1
  1. #1
    eternity's Avatar
    New User

    Status
    Offline
    Join Date
    May 2005
    Posts
    2

    MySQL fields dependance

    hey there!

    if i have mysql table fields called 'YearOfBirth' and 'Age'. how can i make 'Age' be counted automaticly by subtracting 'YearOfBirth' from 'CurrentYear'?

    unfortunately, when i failed to figure that out. besides, it's really uncomfortabe to enter both age and yearofbirth manually plus age expires in a while 8-)

    thanks for your help in advance

    best regards

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: MySQL fields dependance

    try somthing like this:
    Code:
    $age = date("Y") - $yearofbirth;
    if you want to be day spacific:
    Code:
    $age = date("Y") - $yearofbirth;
    if($monthofbirth < date("M")){
      if($dayofbirth < date("M")){
        $age = $age - 1
      }
    }

  3. #3
    eternity's Avatar
    New User

    Status
    Offline
    Join Date
    May 2005
    Posts
    2

    Re: MySQL fields dependance

    emmm... thanx anyway, but that's not exactly what i've been looking for.

    i mean, when i setup the mysql database using phpmyadmin of course, i create some table fields like 'a' , 'b' and 'c'. i want 'b' have value ('c' - 'a'). i'm looking for mysql function or command whatever can make 'b' a subtraction of 'a' out of 'c'.

    i'm interested in doing that and forgetting about the 'b' field. afterwards i will only in enter 'a' and 'c' fields. plus 'b' will always contain correct information.

    i've picked example with birth year and age because that's the key thing of my question - i wonder whether mysql has a possibility to generate field values "on-fly"??? if yes, than HOW ON EARTH???

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: MySQL fields dependance

    You should have a read over this, http://www.keithjbrown.co.uk/vworks/mysql/mysql_p9.shtml , its the mySQL page on generating column values on the fly.

    Be aware, it doesn't actaully keep a column in the database updated, but it does return a column value. But that sounds like what you want anyway.

    Theres a lot in there, numeric functions are about 2/3rds of the way in. Have a good read
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread