Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    6

    Unanswered: less than or equal to (<=) query problem

    Hi,

    Im trying to get a less than or equal to (<=) query to work.

    $query = "SELECT ProductId, Album, Artist, Stock FROM storeritem WHERE Stock="0" ";

    This is the current code i am using. Is there something wrong or missing from this?

    its got all the other code in to display because if i remove the WHERE Stock="0" from the query it shows all the items.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you want what less than or equal to what???

    surely you cannot mean the stock column, because negative stock doesn't make sense

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    unless your stock is a text column I'd try

    Code:
    $query = "SELECT ProductId, Album, Artist, Stock FROM storeritem WHERE Stock=0 ";
    y'don't need quote marks around non text columns
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jan 2009
    Posts
    6
    Sorry i missed bits out of my first post

    I wanted it to <= 10 .

    The problem was i want using quote marks around it. I've done it now, Thanks
    Last edited by MizzHellz; 03-25-09 at 09:51.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    there is no "equals less than or equals" operator, only a "less than or equals" operator

    change this --

    ... WHERE Stock= <=10

    to this --

    ... WHERE Stock <=10

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by MizzHellz
    Code:
    $query = "SELECT ProductId, Album, Artist, Stock FROM storeritem WHERE Stock="0" ";
    You can't embed quotes within quotes unless you escape them or use a different type of quote. If you need quotes here then just change the "0" to '0' and it should work. Lord knows why you want the Stock field to be treated as a string though.

Posting Permissions

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