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);
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, the script is actually right, I had problems in other parts of the script. Thanks anyway.
ASKER
Thanks in advance.