Query Results and not returning empty values

Discussion in 'MySQL' started by kampbell411, May 28, 2010.

  1. #1
    Hi,

    I have a quick question. Im trying to query and and get back all results and not get the fields that are empty.

    I tried this already:
    $sql = "SELECT area, state, cities FROM $tbl_name WHERE (state = '$value') AND (cities != 'NULL') LIMIT $start, $limit";
    HTML:
    Basically, I want to get area, state, and cities for a certain state but I dont want the rows where there are no cities. I want to leave the rows that are completely empty. Thanks.
     
    kampbell411, May 28, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What's that query returning?

    Your 'NULL' is incorrect. Also, you don't need parenthesis around single conditions in your WHERE clause. Only use them if you want to group conditions Ex: WHERE (state = '$value' AND cities != NULL).

    I would try it like this:

    $sql = "
    SELECT area, state, cities
    FROM $tbl_name
    WHERE state = '$value' AND cities <> NULL
    LIMIT $start, $limit";
     
    jestep, May 28, 2010 IP
  3. kampbell411

    kampbell411 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah Sweet. Perfect. Thanks jestep!
     
    kampbell411, May 28, 2010 IP