mysql - Search last 4digits and match the exact or nearest result in the database using php -
i'm working in project need search last 4digit of mobile number , display exact match or if not suggest nearest number it.
example: if user search 8773302 match 4digit database, display 8173302 (from database)
else if not found, display other suggestions like: 8173301, 8173303, 8173304, 8173305 , forth.
code:
$existno = "8673302"; $search = substr($existno, -4); $search_exploded = explode (" ", $search); echo $plan; foreach($search_exploded $search_each) { $x++; if($x==1) $construct .="mobileno '%$search_each%'"; else $construct .="and mobileno '%$search_each%'"; } $constructs ="select * mobilenum $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 * mobilenum $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 can lot in advance
Comments
Post a Comment