sql >> Base de Datos >  >> RDS >> Mysql

Compare la matriz de Facebook de la lista de amigos con la tabla MySQL

$array_with_ids = array('123', '124', '125');
$sql_ids = implode(',', $array_with_ids);

// Select friends already added to db
mysql_query("SELECT * FROM fb_users WHERE fb_id IN (".$sql_ids.")");

// Find friends, that are in your db, but not in the array
mysql_query("SELECT * FROM fb_users WHERE fb_id NOT IN (".$sql_ids.")");

foreach($array_with_ids AS $fb_id)
{
    // Add new friends
    mysql_query("INSERT IGNORE INTO fb_users VALUES (".$fb_id.", ".$name.", ".$stuff.")";
}

Asegúrese de usar un índice principal para fb_id