【问题标题】:php - call to a function on each 5 records from result setphp - 从结果集中对每 5 条记录调用一个函数
【发布时间】:2014-03-25 00:54:48
【问题描述】:

我想使用自适应支付 api,据我所知,我只能将它用于 5 或​​ 6 条记录。 有没有办法自动化这个过程来获取例如 6 条记录调用结果上的函数 然后从 6 条记录重新开始这个过程?

我不能使用任何 php 数据库类,因为我在 wordpress 插件中使用它。 仅供参考:https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results

示例结果:

    Array
(
    [0] => Array
        (
            [seller_paypal1] => yehuda@site.com
            [commission1] => 16.5
        )

    [1] => Array
        (
            [seller_paypal2] => yehuda@site.com
            [commission2] => 16.5
        )

    [2] => Array
        (
            [seller_paypal3] => yehuda@site.com
            [commission3] => 16.5
        )

    [3] => Array
        (
            [seller_paypal4] => yehuda@site.com
            [commission4] => 16.5
        )

    [4] => Array
        (
            [seller_paypal5] => yehuda@site.com
            [commission5] => 16.5
        )

    [5] => Array
        (
            [seller_paypal6] => yehuda@site.com
            [commission6] => 16.5
        )
    [6] => Array
        (
            [seller_paypal7] => yehuda@site.com
            [commission7] => 16.5
        )

)


<?php
// just a fiction way for example
foreach ($records /5 as record) {
  start record 0-5
  adaptive($record['seller_paypal'], $record['commission']);
  //5 records finished start from the 6-11
}

function adaptive($seller_email,$commission) {
// stuff here
}

【问题讨论】:

    标签: php mysql wordpress paypal-adaptive-payments


    【解决方案1】:

    PDOStatement::fetchAll — 返回一个包含所有结果集行的数组或您想要的数组

    【讨论】:

    • 嗨,我在 wordpress 中使用它,所有结果都返回我发布的示例。
    • $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0); var_dump($result); //使用var_dump();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    相关资源
    最近更新 更多