从数组更新记录

时间:2012-06-27 03:28:31

标签: php mysql

我在更新数组中的记录时遇到问题。当我去更新时,我只得到第一个数字。例如,如果实际值是58,我只得到5插入

以下是我的代码,下面有进一步说明:

$bidArr = $tmpArr;

foreach($tmpArr as $key => $val)
{
$sqlEp = "select sum(endpoints_c), account_id1_c as id from accounts_cstm as ac join accounts as a on a.id = ac.id_c 
where account_id1_c ='$val' and (status_c IN ('active','llp')) and deleted='0'";
$rowEp = $db->query($sqlEp);
$recordEp = $db->fetch_row($rowEp);

$bidArr[$key]['sold_ep_c'] = $recordEp[0];

//print "<pre>EP";
//print_r($recordEp);

}

foreach($bidArr as $key => $val)
{

$data['sold_ep_c'] = $val['sold_ep_c'];
$db->query_update(TABLE_ACC, $data, "id_c='".$key."'");
print "<pre>EP";
print_r($key);
print_r($data);
}

当我取消注释第一个print_r时,发生了什么:

EPArray (     [0] =&gt; 16     [1] =&gt; 51067d38

哪个是对的。但是,如果我将其评论出来并取消注释我得到的第二个:

51067d38 (     [sold_ep_c] =&gt; 1 )

为什么这剥离了第一个数字?

1 个答案:

答案 0 :(得分:0)

根据聊天...您的数组未初始化。 第一个循环中$bidArr[$key] = array();