This is my php code
<?php
if(isset($_GET['name']))
{
$var = $_GET['name'];
$newvar =str_replace (" ", "", $var);
$sql = "SELECT varpin, ABS( varpin - '".$newvar."' ) AS pin FROM tbladstore ORDER BY pin LIMIT 5";
}
?>
Here name have value 682 031.In table varpin is stored as xxx xxx.Here i want to remove the space of varpin value when selecting using query.
That is after this step
`$newvar =str_replace (" ", "", $var);`
the $newvar have the format xxxxxx.so i also need varpin is in this format for finding nearest values of a given pin number.How can i do this?
In db the varpin is in varchar type.I also need this field as only varachar not changed to other type.
You could use
REPLACE(varpin, ' ', '')to get rid of all spaces invarpincolumn.And then use
CONVERT(value, DECIMAL)to make it into a numeric type.Documentation: