SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    the table is library,, branch is one of several nv, bh, gp, etc.
    //first i get the current date.
    $Today=date("Y-m-d");
    //query the db

    $query = "select * from library"

    . " where branch='nv'"
    //the following line is the problem.
    . " and date < $Today"
    . " order by date ";
    $result= mysql_query($query)
    or die ("Cannot execute query");

    the lt and gt do not work the way shown in page 54 of MySQL and logically they should. any idea what i am doing wrong?

    thanks ed

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem is that you aren't putting quotes around your date string. Try the following in MySQL:

    mysql> SELECT 2000-07-20;

    mysql> SELECT "2000-07-20";

    Notice that, in the first case, MySQL treats the expression as an arithmetic operation and subtracts 27 from 2000 to give 1973. In the second case, the quotes tell MySQL that the expression is to be treated as a literal string, and no calculation is performed.

    Thus, your line can be fixed by adding quotes around the date value:

    . " and date < '$Today'"


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  3. #3
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks.

    sometimes i get to tracking on a problem and the obvious goes unobserved.

    thanks again.

    ed


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
  •