If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > less than or equal to (<=) query problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-09, 21:09
MizzHellz MizzHellz is offline
Registered User
 
Join Date: Jan 2009
Posts: 6
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.
Reply With Quote
  #2 (permalink)  
Old 03-25-09, 03:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you want what less than or equal to what???

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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-25-09, 03:45
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,259
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 03-25-09, 08:44
MizzHellz MizzHellz is offline
Registered User
 
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 08:51.
Reply With Quote
  #5 (permalink)  
Old 03-25-09, 08:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 03-25-09, 09:07
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On