peabrainj Posted May 24, 2006 Posted May 24, 2006 I'm trying to get a list of products that are already available but I can't figure out the SQL syntax to check if a variable is NULL. I'm using an RSS feed contribution (not sure what the name of it is). It doesn't screen for products that are coming soon. I'm trying to add a new product each day (so search engines get a steady stream of new content). It's a bit of a pain - I'd like to add 10 at a time, then have a new one show up on my site every day. I've got everything working except the RSS feed, which currently includes products that aren't available. Anyway here's my SQL query from rss.php: SELECT products_id, products_model, products_image, products_price, products_tax_class_id FROM products WHERE products_status=1 AND products_date_available < '2006-05-22 00:00:00' OR products_date_available = NULL ORDER BY products_id DESC LIMIT 20 Most of my products have a value of NULL in the field products_date_available. But now I'm using products_date_available to indicate when my site should start displaying the product. So I need to list all the products that are active (products_status=1) and either have products_date_available=NULL or products_date_available < today. (In the actual code I use the php now() function to generate the current date. i've been googling this for hours but every page that mentions SQL mentions the word NULL, so I have no way to find what I'm actually looking for! Anyway thanks in advance for any help! peace Quote
yankeguy Posted June 1, 2006 Posted June 1, 2006 You just need to write "IS NULL" instead of "= NULL". For example, "WHERE products_date_available IS NULL". Oppositely, if you need to find a row where a certain field is not null, you would write "NOT NULL" as the argument (rather than "IS NOT NULL" or "!= NULL"). Paul I'm trying to get a list of products that are already available but I can't figure out the SQL syntax to check if a variable is NULL. I'm using an RSS feed contribution (not sure what the name of it is). It doesn't screen for products that are coming soon. I'm trying to add a new product each day (so search engines get a steady stream of new content). It's a bit of a pain - I'd like to add 10 at a time, then have a new one show up on my site every day. I've got everything working except the RSS feed, which currently includes products that aren't available. Anyway here's my SQL query from rss.php: SELECT products_id, products_model, products_image, products_price, products_tax_class_id FROM products WHERE products_status=1 AND products_date_available < '2006-05-22 00:00:00' OR products_date_available = NULL ORDER BY products_id DESC LIMIT 20 Most of my products have a value of NULL in the field products_date_available. But now I'm using products_date_available to indicate when my site should start displaying the product. So I need to list all the products that are active (products_status=1) and either have products_date_available=NULL or products_date_available < today. (In the actual code I use the php now() function to generate the current date. i've been googling this for hours but every page that mentions SQL mentions the word NULL, so I have no way to find what I'm actually looking for! Anyway thanks in advance for any help! peace Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.