Results 1 to 6 of 6
  1. #1
    ABW Ambassador writerguy's Avatar
    Join Date
    January 17th, 2005
    Location
    Springfield, Missouri, USA
    Posts
    3,248
    PHP question about NOT ISNULL() condition
    I'm really stretching the bounds of my meager PHP knowledge here. But here goes:

    I'm displaying products from a very large datafeed I have in a MySQL table. Within the table is a field of images for each item in the datafeed, which is named "BigImage." BUT -- in this particular datafeed, there are lots of items with no BigImage available.

    How would I structure the SELECT command to display products with a given "Name" condition, yet ONLY display those products with BigImages? I googled around and came up with this:

    $query = "SELECT Name, Description, Link, BigImage FROM table where NOT ISNULL(BigImage) and Name like '%xxxxx%' ORDER BY RAND()";

    That selects products and later in the script I have echo statements to create a table on my web page that displays what has been selected -- BUT, it displays everything that matches the "Name" condition (like '%xxxxx%'), and ignores the NOT ISNULL(BigImage) condition completely.

    In other words, this "solution" doesn't work for me -- it continues to display lots of items that lack images.

    Comments? Solutions?? HELP!!!!

    Thanks
    Generate more fake news.

  2. #2
    ABW Ambassador MoneyBusiness's Avatar
    Join Date
    March 14th, 2006
    Posts
    2,051
    Testing for NULL values in all kinds of code can be tricky sometimes, simply b/c NULL doesn't always mean "empty". Give this a shot instead:

    $query = "SELECT Name, Description, Link, BigImage FROM table where BigImage != "" AND Name like '%xxxxx%' ORDER BY RAND()";

    Hope that works for you.

  3. #3
    ABW Ambassador writerguy's Avatar
    Join Date
    January 17th, 2005
    Location
    Springfield, Missouri, USA
    Posts
    3,248
    Quote Originally Posted by MoneyBusiness
    Testing for NULL values in all kinds of code can be tricky sometimes, simply b/c NULL doesn't always mean "empty". Give this a shot instead:

    $query = "SELECT Name, Description, Link, BigImage FROM table where BigImage != "" AND Name like '%xxxxx%' ORDER BY RAND()";

    Hope that works for you.
    Thanks. If I use single quote marks ('') after "=" it works fine. If I use double quote marks (""), it messes up with this awesome error message:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/xxxxx/public_html/xxxxx.php on line 11

    But with the single quote marks it does the trick. So do I get an error with the double quote marks?
    Generate more fake news.

  4. #4
    Affiliate Manager adambha's Avatar
    Join Date
    October 20th, 2006
    Posts
    301
    FWIW, this is really a MySQL question rather than a PHP question.

    Anyway, enjoy!

    PHP Code:
    $query "SELECT Name, Description, Link, BigImage FROM table where BigImage is not null and Name like '%xxxxx%' ORDER BY RAND()"

  5. #5
    ABW Ambassador MoneyBusiness's Avatar
    Join Date
    March 14th, 2006
    Posts
    2,051
    Quote Originally Posted by writerguy
    Thanks. If I use single quote marks ('') after "=" it works fine. If I use double quote marks (""), it messes up with this awesome error message:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/xxxxx/public_html/xxxxx.php on line 11

    But with the single quote marks it does the trick. So do I get an error with the double quote marks?
    Doh, that would make sense. You get error messages with double quotes because that's what the main SQL command is enclosed in "SELECT...ETC", and that's why singles work.

    Anyway, good to hear it works!

    Take care

  6. #6
    ABW Ambassador writerguy's Avatar
    Join Date
    January 17th, 2005
    Location
    Springfield, Missouri, USA
    Posts
    3,248
    Quote Originally Posted by adambha
    FWIW, this is really a MySQL question rather than a PHP question.

    Anyway, enjoy!

    PHP Code:
    $query "SELECT Name, Description, Link, BigImage FROM table where BigImage is not null and Name like '%xxxxx%' ORDER BY RAND()"
    Yup, you're right. After I had opened the thread and made my OP, I realized I should have said MySQL -- but, alas, by then it was too late.
    Generate more fake news.

  7. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP question - include(file.php) with variables
    By teezone in forum Programming / Datafeeds / Tools
    Replies: 8
    Last Post: September 4th, 2009, 04:54 PM
  2. PHP Question
    By mopek in forum Programming / Datafeeds / Tools
    Replies: 4
    Last Post: August 23rd, 2006, 04:51 PM
  3. PHP Question
    By Doug247 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: March 31st, 2004, 10:20 AM
  4. Help Please - .php Question
    By ~Michelle in forum Programming / Datafeeds / Tools
    Replies: 12
    Last Post: March 18th, 2004, 02:52 PM

Posting Permissions

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