0

3つのクエリの結果を、非常に具体的な方法で任意の日数に分散させようとしています。各配列からの各結果は1回の電話を表し、1日あたり合計18回の電話が必要です。

1日あたり合計18件の結果が必要です。

8 $active_costco results
4 $inactive_costso results
3 $bashas results
3 $afs results

$active_costco returns 321 total results
$inactive_costco returns 119 total results 
$bashas returns 64 total results
$afs returns 47 results

結果の総数は1日あたり18である必要があるため、$afsまたは$inactive_costcoがなくなった場合は、$active_costcosを18に入力します。

これが私が現在持っているphpです(active_costcosを1日あたり8つに分割するだけです)

        $active_costco = sql::results($query);

$inactive_costco = sql::results();

$bashas = sql::results("");

$afs = sql::results("");
$date = date('Y-m-d');
$str = 'INSERT pharmacy.dbo.hotlist (employee_id, store_id, follow_up_date, created_at, status, urgency)VALUES';
for ($i = 0; $i < count($active_costco); $i++)
{
    if ($i%8 == 0)
    {
        $date = date('Y-m-d', strtotime($date . '+1 Weekday'));
    }
    $str .= "('0CS',". $active_costco[$i]['id'] . ", '$date', '". date('Y-m-d H:m.s') . "', 1, 3)";
    $str .= ($i == count($active_costco)-1)? '': ',';
    $str .= '<br />';
}
echo $str;

どんな助けでもいただければ幸いです。ありがとう、マイク

4

1 に答える 1

1

これに少し時間を費やした後、私が思いついた解決策は次のとおりです。

$str = 'INSERT pharmacy.dbo.hotlist (employee_id, store_id, follow_up_date, created_at, status, urgency)VALUES';
do 
{
    $date = date('Y-m-d', strtotime($date . " +1 Weekday"));
    $today = array();
    for ($i = 0; $i < 3; $i ++)
    {
        $basha = array_pop($bashas);
        $associated = array_pop($afs);
        if (!empty($basha))
            $today[] = $basha;
        if (!empty($associated))
            $today[] = $associated;
    }
    for ($i = 0; $i < 4; $i++)
    {
        $inactive = array_pop($inactive_costco);
        if (!empty($inactive))
            $today[] = $inactive;   
    }

    $count = 18 - count($today);
    for ($i = 0; $i < $count; $i++)
    {
        $active = array_pop($active_costco);
        if (!empty($active))
            $today[] = $active;
    }

    $calls_left = count($active_costco) + count($inactive_costco) + count($bashas) + count($afs);
    foreach ($today as $v)
    {
        echo "Store ID = " . $v['id'] . " Date = " . $date . "<br />";
    }
}while ($calls_left > 0);

通過し、各配列 (指定された数) から要素をポップします。配列が空の場合 (ポップするものが何もない)、何も追加されません。次に、today 配列内の呼び出しの数をカウントし、18 からそれを引き、$active_costsco から残りの呼び出しを取得します。

入力してくれたすべての人に感謝します。

于 2012-10-16T21:01:47.933 に答える