MySQL query help

Discussion in 'PHP' started by Im The ONE, Jul 5, 2009.

  1. #1
    Hi,

    Is there a way to compare a mysql field x,y,z with array y,x,z

    It should check if the field has every character in the array

    Cheers
     
    Im The ONE, Jul 5, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maybe you could do something along these lines

    $array = array('x', 'y', 'z');
    $query = "SELECT * FROM table";
    $result = mysql_query($query) or die(mysql_error());
    
    while($row = mysql_fetch_array($result){
    foreach ($array as $a){
    while(charExist){
    $charExist = strpos($row['field'], $a);
    if (charExist == true) $total ++;
    }
    if (total == sizeof($array)){
    echo "all characters exist";
    }
    }
    }
    
    PHP:
     
    wd_2k6, Jul 5, 2009 IP