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);

  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);
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Giovanni GCTOCommented:
first you are missing a $ sign inside your if statement (see that TempHigh?),

second, it is an ugly approach. I would do something like this:

    $WildLow = substr_count($LOW, "*");
    $WildHigh = substr_count($HIGH, "*");
    $TempLow = str_replace("*", "0", $LOW);
    $TempHigh = str_replace("*", "0", $HIGH);

    // query with wildcards
    $Query .= "Num >= '$TempLow'";
    $Query .= " AND ";
    if ($WildHigh > 0)
      $Query .= "Num <= '$TempHigh'";
      $Query .= "1"; // always true

not sure i really understood you problem, but this may probably help.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yooniquelyAuthor Commented:
Why is the last one always true?

Thanks in advance.
Otherwise you will get something like:

Num >= '10' (your $TempLow)
AND (NOTHING... because $TempHigh is not >0)...

that is why he puts in the 1, you will then get AND 1 at the end... wich is the TRUE ThG speaks about
yooniquelyAuthor Commented:
Yeah, the script is actually right, I had problems in other parts of the script. Thanks anyway.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.