Magiccupcake
12 Mar 2009, 01:17 AM
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
Alan
12 Mar 2009, 08:50 AM
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.
$number = implode("",explode(",",$number));
2. You could replace the "," with nothing.
str_replace(",","",$number);
3. You could use a custom function to search for the "," and remove it.
function removeComma($string)
{
$newstr = '';
$length = strlen($string);
for($i=0;$i<$length;$i++)
{
$char = substr($i,1,$string);
if($char != ",")
$newstr .= $char;
}
return $newstr;
}
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.