Submit Your Article Forum Rules

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Show date from field

  1. #1
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941

    Show date from field

    Hi

    I am a beginner in database so I hope anyone can show me the direction to resolve this. I am confused as why I am unable to show the date from the field in table.

    I have inserted in the table for field as date1 and the date1 is showing as 19900328 (yyyymmdd).

    $date1 = $year1.$month1.$day1;
    $birthdate1 = " (Birthdate: ".$month1." ".$day1.", ".$year1.") ";

    When I tried to echo $birthdate1, it shows blank.

    Anything wrong with what I am doing? Thanks a million!
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

  2. #2
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,826
    First thing that jumps out is use of the delimiters (.) in the variable names:
    $birthdate1 = " (Birthdate: ".$month1." ".$day1.", ".$year1.") ";
    Add:

    And the use of quotes around the variable names...

    But I am not really the one to be answering this, 'cause I'm just guessing. Apologies, @edhan.
    Last edited by weegillis; 01-31-2012 at 11:17 PM. Reason: add

  3. #3
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941
    Thanks weegillis.

    I will try it out and see if it works as I am still a beginner in this. Any help will be appreciated from anyone including your guessing. Hope it works! (Cross my fingers!)

    Sorry, it does not work though! Sob!
    Last edited by edhan; 02-01-2012 at 01:12 AM. Reason: Test but does not work
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

  4. #4
    WebProWorld MVP williamc's Avatar
    Join Date
    Jul 2003
    Location
    On a really big hill in Kentucky
    Posts
    4,721
    edhan can you show more of the actual code. I do not see it pulling from a database, be it flatfile, mysql, mssql or otherwise.
    William Cross
    Web Development by Those Damn Coders
    Firearm Friendly Websites because our constitution matters

  5. #5
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941
    Williamc, I am just starting to write this database and see if it can output the Birth date from the database.

    Here is what I am trying to do.

    I have created a database Table with 2 fields - date1 and person.
    Field in column for date1 is 19790103, 19710304, 20010923, etc. And the field for Person in column is Peter, Andrew, William, etc corresponding to their date of birth.

    What I want to do next will be extracting the date to show in HTML as: Birthdate: 01 03, 1979 for Peter when I submit this in the form with that date of birth. This form in php submission using:

    <SELECT NAME="day1"> with option 1 to 31
    <SELECT NAME="month1"> with option 1 to 12
    <SELECT NAME="year1"> with option 1950 to 2011

    When submitted, it should be showing the date of birth in that format extract out from the database as - Birthdate: 01 03, 1979 for Peter and if select date of birth 19710304 then it will be Andrew and should be displaying as - Birthdate: 03 04, 1971

    Hope this explanation is clear. I am just starting to write this and encountering the problem of not able to echo the birthdate when selecting the birth date upon submission.
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

  6. #6
    WebProWorld MVP williamc's Avatar
    Join Date
    Jul 2003
    Location
    On a really big hill in Kentucky
    Posts
    4,721
    Edhan: you keep saying database, then showing me html. Let's try this an easier way.

    what database system are you using?
    William Cross
    Web Development by Those Damn Coders
    Firearm Friendly Websites because our constitution matters

  7. #7
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941
    I am using MySQL.

    Here is how I create the table for MySQL.

    CREATE TABLE match (
    date1 varchar( NOT NULL,
    person varchar(25) NOT NULL
    );

    ## Data to insert into match table

    INSERT INTO match VALUES ( '18990101', 'Peter');
    INSERT INTO match VALUES ( '19000131', 'Robin');
    INSERT INTO match VALUES ( '19010219', 'Charles');
    INSERT INTO match VALUES ( '19020208', 'Tom');
    INSERT INTO match VALUES ( '19030129', 'Robert');
    INSERT INTO match VALUES ( '19040216', 'William');
    INSERT INTO match VALUES ( '19050204', 'Scott');
    INSERT INTO match VALUES ( '19060125', 'Ho Chang');

    The date1 has 8 instead of the smiley.
    Last edited by edhan; 02-01-2012 at 07:57 PM.
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

  8. #8
    WebProWorld MVP williamc's Avatar
    Join Date
    Jul 2003
    Location
    On a really big hill in Kentucky
    Posts
    4,721
    ok, so mysql, now are you even connecting to the database and pulling the data from it at all?

    IE:

    Code:
    	$db = @mysql_connect('localhost', 'dbuser', 'dbpass');
    	@mysql_select_db('dbname', $db);
    
    	$result = mysql_query("SELECT * FROM  `match` WHERE `person` = '$person'", $db);
    	$row = mysql_fetch_assoc($result);
    	
    	$my_date = date("m d Y", $row['date1']);
    The data is not just magically there, you have to pull it from the table in order to use it.
    William Cross
    Web Development by Those Damn Coders
    Firearm Friendly Websites because our constitution matters

  9. #9
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    762
    Since you are not storing the date as a date but as a varchar, there's not a lot you can do with it in terms of comparisons or specific selections. If you setup that field in the database as a date then Wiliam's use of the date function above will work.

    I can't see anything wrong with the code in your original post. If $date1 has the correct value, I don't see why $birthdate1 doesn't. Or is there something else you're not telling us?
    Dynamic Software Development
    www.activeminds.ca

  10. #10
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941
    My intention of writing this is to start with fetch from the database the date1 and person I have manually input into the MySQL. Now I am just testing to see if I can fetch it using the php submission of date of birth to display on the web page. Thereafter I will create additional date2 and person2 to fetch and doing comparison.

    But I really do not understand how I can extract (fetch) it using the php submission. Guess it is too complicated for me and I will continue to search online to see if there is any other solution or see if anyone else here understands what I want to give suggestion. Thanks anyway!
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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