I'm working in a project where i need to search for the last 4digit of a mobile number and display the exact match or if not suggest the nearest number to it.
Example: if user will search for 8773302 it match the 4digit from the database, it will display 8173302 (from database)
else if not found, it will display other suggestions like: 8173301, 8173303, 8173304, 8173305 and so forth.
CODE:
$existNo = "8673302";
$search = substr($existNo, -4);
$search_exploded = explode (" ", $search);
echo $plan;
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="mobileno LIKE '%$search_each%'";
else
$construct .="AND mobileno LIKE '%$search_each%'";
}
$constructs ="SELECT * FROM mobilenum WHERE $construct OR status = '0'";
$run = mysql_query($constructs);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
{
header ("LOCATION:suggestedNo.php");
}
else
{
$getquery = mysql_query("SELECT * FROM mobilenum WHERE $construct") or die (mysql_error());
//Table Results
while($runrows = mysql_fetch_assoc($getquery))
{
$verifyMobileNo= $runrows ['mobileno'];
$verifyMobileStat= $runrows ['status'];
}
$matchMobileNumber = $verifyMobileNo;
if ($verifyMobileStat == "0"){
header ("LOCATION:matchNo.php");
}
else {
header ("LOCATION:suggestedNo.php");
}
}
Hope somebody can help thanks a lot in advance