I have a database having 10000 users with unique phone numbers.And when ever a new user registers I'm trying to match all his contacts (nearly 200 to 500) with my existing data so that I can find his friends (like whats app)
Currently I m doing using foreach and its very slow, so I need help in finding a reliable solution for this which can reduce the time taken for multiple queries.
Please find the code below that i m using.
$rawdata= file_get_contents('php://input');
$Matchedcontacts = array();
$jsonArray = json_decode($rawdata);
foreach ( $jsonArray as $value)
  {
  $contactNumber = ($value->num);
  $emil= ($value->email);
  $name=mysql_query("select * from TBL_USER where  phone='".$contactNumber ."' OR email='".$email."'");
  while ($nameres= mysql_fetch_array($name))
  {
   $Matchedcontacts [] = array('username'=>$nameres['username'], 'userid'=>$nameres['c_id']);
  }
}
echo json_encode ($Matchedcontacts );
EDIT: also I'm passing a local id with the each record I'm sending. So after a match, how can I map the matched record with the particular local ID?
 
     
     
     
     
    