All values in a SQL field

Discussion in 'PHP' started by mnymkr, Jun 19, 2007.

  1. #1
    I am setting some default values on a call to a database

    I want the defualt to be Everything in the array

    is there like a

    WHERE color = ALL or something like that

    I am guessing

    WHERE color = "" will return only rows where the values is Null
     
    mnymkr, Jun 19, 2007 IP
  2. -CP-

    -CP- Well-Known Member

    Messages:
    181
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    140
    #2
    tried WHERE color = "%"?

    % is a wildcard so should return all rows.


    -CP-
     
    -CP-, Jun 19, 2007 IP
  3. Will Morgan

    Will Morgan Peon

    Messages:
    70
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You could try fulltext matching.

    onlamp.com/pub/a/onlamp/2003/06/26/fulltext.html

    Just add the fulltext property to the field which you're looking for, and then implode the array like so:

    
    $colours = array('red', 'green', 'blue');
    
    $colour_search_string = implode(',', $colours);
    
    mysql_query("SELECT * FROM database WHERE MATCH(color) AGAINST ('".$colour_search_string."')");
    
    PHP:
    I hope this helps.

    (Sorry I couldn't provide a full link, since this forum has a stupidly restrictive posting rule for newbies. They obviously don't think past the fact that some people might want to provide useful data.)
     
    Will Morgan, Jun 19, 2007 IP
  4. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #4
    nice that might work

    i just did a != ISSET and gave null as the result else do the query statement but your way is much simpler
     
    mnymkr, Jun 19, 2007 IP
  5. Circadian

    Circadian Peon

    Messages:
    200
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What about where color != ""
     
    Circadian, Jun 19, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    That's what he should be using...

    Besides, CP, WHERE color = "%" won't work, wildcards are only applicable when LIKE is used, e.g.:

    WHERE color LIKE '%'
     
    krt, Jun 19, 2007 IP