duanrou5680 2016-01-20 17:57
浏览 82


I have a query a Wordpress include which does the following:

        $sql = "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'merchant_id' LIMIT 6";
$results = $wpdb->get_results($sql);
     foreach ($results as $row)
                    echo $row->meta_value . ",";
                    //sprintf("SELECT * FROM retailers WHERE advertiserId = '%s'", $row->meta_value);

    //clean all results

It parses all pages custom fields (merchant ID numbers), and returns any unique distinct values, separated by a comma. This bit works great.

ie: The above may return: 1301,345,723,134,1435

What I also have is a separate MySQL table of about 20 fields, three of which are the MerchantID, programmeName, and commissionMax. Each value from the CSV correlates with the MerchantID in the database.

Regardless of the amount of merchant ID's that appear in the CSV - I need to parse them all, but show the three highest commission rates (commissionMax), as well as the programmeName.

I managed to get connected to my external database and retrieve the appropriate values (using the commented code above) however this showed all of the retailers information.

Any advice?

  • 写回答

1条回答 默认 最新

  • drk7700 2016-01-20 18:03

    Use the following query with limit:

    SELECT *                             // select all fields
    FROM table_name                      // from your table
    WHERE MerchantID IN (your_ids_here)  // IDs received from previous query or wherever
    ORDER BY commissionMax DESC          // descending sort by commissionMax field
    LIMIT 3                              // take first 3 results
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 关于模型训练的一个问题
  • ¥15 装了几千台服务器从来没遇到这种问题,哎看下哪位帮我解决吧
  • ¥15 单片机程序上的困难问题
  • ¥15 请教某软件缓存Ts文件破解合并mp4的方法
  • ¥15 求小游戏炸弹人中关于敌人的C++代码
  • ¥15 拿到这个服务器最高权限有偿
  • ¥50 来个抓app跳转支付宝转链接的
  • ¥15 remotes安装提示没有description文件
  • ¥15 AttributeError: 'NoneType' object has no attribute 'drop_duplicates'报错
  • ¥15 以下代码,运行结果报错