Link to home
Start Free TrialLog in
Avatar of yooniquely
yooniquely

asked on

wildcard and mysql query - select all that matches 4* to 47* etc

I'm fairly new to PHP and I have a question.

I am trying to select all that matches the range [some number] to [some number] and allow the range to have wildcards inside a function. Variables are passed in (user input)

    $Query = "SELECT Num FROM table WHERE ";    
   
    // for wild cards
    $WildLow = substr_count($LOW, "*");
    $WildHigh = substr_count($HIGH, "*");
    $TempLow = str_replace("*", "", $LOW);
    $TempHigh = str_replace("*", "9999999999", $HIGH);

    // query with wildcards
    if ( ($WildLow > 0) || ($WildHigh > 0) ) {
      $Query .= " Num >= '$TempLow' ";
      $Query .= " AND ";
      $Query .= " Num <= 'TempHigh' ";
      GetRangeArray ($List, $Index, $Query);
      return;
    }

  However I keep getting invalid as its result whenever i pass in "*" as the range input.

  Any suggestions? Thanks.

ALso, what does this regular expression mean?       $Result = ereg("^[0-9\*]{1,". "10" . "}$", $Num);
ASKER CERTIFIED SOLUTION
Avatar of Giovanni G
Giovanni G
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yooniquely
yooniquely

ASKER

Why is the last one always true?

Thanks in advance.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, the script is actually right, I had problems in other parts of the script. Thanks anyway.