我试图在任何天数中以非常具体的方式分散3个查询的结果。每个阵列的每个结果代表1个电话,我希望每天总共有18个电话。
我每天需要总共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
我需要每天的结果总数为18,因此,如果没有$ afs或$ inatevive_costco's,请用$ active_costcos填充至18 这是我当前拥有的php(它仅将Active_costcos划分为每天8个) 任何帮助将不胜感激。谢谢,Mike $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;
花了一点时间,这是我提出的解决方案:
$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);
它通过并弹出每个数组的元素(指定的数字)。如果数组为空(没有什么可弹出),则不会添加任何内容。然后,它计算到今天的数组中的调用数量,从18中减去,并从$ active_costsco中获取其余的呼叫。
感谢所有投入输入的人。