SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking the value of the Date

    I have field called "c_date" for closing date. Not all rows have a closing date. Because of this MySQL assigns a value of 0000-00-00 00:00:00 to the field. When I print the closing date to a web page I don't want to show all those 0's so I wrote the following:

    while ($row=mysql_fetch_array($results){
    $cdate = $row["c_date"];
    if ($cdate = "0000-00-00 00:00:00")
    {
    $cdate = " ";
    }
    echo ($cdate);
    }

    This code results in the removal ALL closing dates including ones that don't equal 0000-00-00 00:00:00.

    Help!!! What am I doing wrong? Is there a better way to do this?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When making comparisons you need to use == not = so your code should look like

    PHP Code:
    if ($cdate == "0000-00-00 00:00:00"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Wolverhampton, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if ($cdate [red]==[/red] "0000-00-00 00:00:00")

    the = sign makes $cdate equal to 0000-00-00 00:00:00 and so evaluates to true what ever the date because 0000-00-00 00:00:00 is a non-empty string...

    however == compares the too things and returns true or flase depending on whether they equal each other or not...

    beachball

    is there a === that compares value and data type?? or is that me makin' stuf up lol

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Wolverhampton, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    freddy seems to do this too everyone...

    1 min in it ffs...

    beachball

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1 min in it ffs...
    ????


    I guess you need to learn to type faster
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CyberFuture you might think about making that DATE column NULL. then records w/o a closing DATE would be NULL (in PHP !isset($column)) rather than 0s.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  7. #7
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its always the little things that trip me up.

    I do have the field set to NULL but the O's appear anyways. I think its a MyPHPAdmin thing. I'm currently using MyPHPAdmin to create records for testing purpose. Also the the records will be inserted and updated via MS Access2000 (don't ask) and I think this may be also causing the problem.

    Anyways thanks for all your help and suggestions.


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
  •