Originally Posted by
Magiccupcake
I have a mysql database set up and one of the rows has numbers like "34,000".
I want to pull the info that is less than 20,000. What would be the best way to do that?
If the commas were not there it would be as simple as "Where $number > 20000". but with the commas it seems a little trickier.
Thanks
3 methods off the top of my head.
1. Use the explode function to break it into two elements of an array and then glue it back together with the implode function.
PHP Code:
$number = implode("",explode(",",$number));
2. You could replace the "," with nothing.
PHP Code:
str_replace(",","",$number);
3. You could use a custom function to search for the "," and remove it.
PHP Code:
function removeComma($string)
{
$newstr = '';
$length = strlen($string);
for($i=0;$i<$length;$i++)
{
$char = substr($i,1,$string);
if($char != ",")
$newstr .= $char;
}
return $newstr;
}