dongmuyuan3046 2013-04-14 23:52
浏览 32
已采纳

将非MySQL列表/数组/数据与MySQL行进行比较?

I'm developing an iOS social networking app. I'm currently building "Find Friends" section.

I have a "users" table which is something like this:

-user_id  -user_name  ... -twitter_id   -facebook_id   -instagram_id
948913    yagiz           2134421       2132412        4314124312

Now for example when I try to find friends, app does this in the background:

  • Get the list of whole followings of current user from selected social networking app(Twitter/Facebook/Instagram). Response is a simple array which consists of user ids.

  • For each Twitter/Facebook/Instagram id run a query that checks if it is in app database.

Currently this works well. But I kinda think that this isn't efficient. Because if the user follows 5K people on Twitter/Facebook/Instagram app runs 5K query.

So I'm asking which is the best way to compare non MySQL list/array/data with MySQL rows?

  • 写回答

1条回答 默认 最新

  • douchengjue9892 2013-04-15 01:05
    关注

    You can perform a single query using

    WHERE ... IN('1', '2') 
    

    If you have an array of the ids , you can do it like this:

    $twitterIds = array(
        1234,
        1235,
        1236
    );
    
    // $twitterIdString = '1234','1235','1236'
    $twitterIdString = "'" . implode("','", $twitterIds) . "'";
    
    // $queryStub = WHERE `-twitter_id` IN('1234','1235','1236')
    $queryStub = "WHERE `-twitter_id` IN(" . $twitterIdString . ")";
    

    This will return only the twitter users that are in your database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭