SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    neglect empty variables

    Hi guys,

    I have this query that's selecting data from my database:
    PHP Code:
    $sql_blabs mysql_query("SELECT username,firstname,blab,date,image FROM testimonials WHERE ....... ORDER BY date DESC LIMIT 5"); 
    But I would like it to select the data where blab has info in it. I mean, the query should be selecting those blabs that have data and not the empty ones. How do I do that?
    What do I write after WHERE....

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adamschroeder View Post
    Hi guys,

    I have this query that's selecting data from my database:
    PHP Code:
    $sql_blabs mysql_query("SELECT username,firstname,blab,date,image FROM testimonials WHERE ....... ORDER BY date DESC LIMIT 5"); 
    But I would like it to select the data where blab has info in it. I mean, the query should be selecting those blabs that have data and not the empty ones. How do I do that?
    What do I write after WHERE....
    you can either control the output in your php or in mysql do somthing like:

    Code:
    balb IS NOT NULL

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Check out MySQL's operators.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I listened to both of you and solved it.
    I wrote this:
    mysql_query("SELECT * FROM testimonials WHERE blab IS NOT NULL ORDER BY date DESC LIMIT 5");
    and I changed blab in sql database to be NULL by defaul.


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
  •