php foreach循环与数组

时间:2013-01-15 08:28:39

标签: php mysql loops foreach

我的语法如下:

function get_outstandingchecking($db)  
{    
    $result = $db->query("  SELECT distinct(haulier) as haulier from v2loads where  adminstatus='captured' and  DATEDIFF(now(), capturedate) >4 group by haulier,DATEDIFF(now(), capturedate) order by DATEDIFF(now(), capturedate) desc  "); 
    return $result; 
}

$outstandingchecking = get_outstandingchecking($db); 
$outstandingchecking_row_count = $outstandingchecking->rowCount();

if ($outstandingchecking_row_count > 0) {
    $i=0;

    foreach ($outstandingchecking as $instance) {
        echo $instance[$i];
        $i=$i+1;
        //syntax email relevent haulier
    }
}

$ result查询获取受影响的值数组(承运人)。然后,我想使用每个返回的“承运人”并向他们发送电子邮件通知。

输出只显示查询结果中的第一个值,如何让它在foreach循环中显示所有值?

一如既往地谢谢,

2 个答案:

答案 0 :(得分:2)

尝试

foreach($outstandingchecking as $instance){ 
   echo $instance[0];
}

使用foreach时不需要$ i

答案 1 :(得分:0)

试试这段代码。

$final=array();
foreach($outstandingchecking as $instance){ 

$final[]=$instance;

$i=$i+1;

//syntax email relevent haulier

}

print_r($final);