Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Compare a lista de amigos do Facebook com a tabela 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.")";
}

Certifique-se de usar um índice primário para fb_id