2011-11-28 106 views
0

您好我有这种麻烦试图保存在表中的多个行“通知”与客户表IDS但它只救我一行这是我的代码:麻烦试图保存在表中的多个行在php + mysql

$customers = tep_get_customers(); 
    $count = 0; 
for ($i=0, $n=sizeof($customers); $i<$n; $i++) { 
    $count ++; 
$insert_str_cony .= $customers[$i]['id']; 
$split_customers_id = explode("||", $insert_str_cony.'||', -1); 
$values .= "('','" . tep_db_input('1') . "', now(), '" . tep_db_input($products_id) . "', '" . tep_db_input($split_customers_id[$count]) . "'),"; 
$db_values = substr_replace($values, '', -1, 1); 
} 
       if ($action == 'insert_product') { 
       tep_db_query("insert into notifications (notify_id, prod_notify, notify_added, prod_id, customers_id) values ". $db_values); 
       } elseif ($action == 'update_product') { 
       tep_db_query("update notifications set prod_notify = '" . tep_db_input('1mod') . "', notify_last_mod = now(), prod_id = '" . $HTTP_GET_VARS['pID'] . "', customers_id = '" . tep_db_input($customers['customers_id']) . "'"); 
      } 

这是函数tep_get_customers();

function tep_get_customers() { 
    $customers_query = tep_db_query("select distinct customers_id from " . TABLE_CUSTOMERS . ""); 
    while ($customers = tep_db_fetch_array($customers_query)) { 
     $customers_array[] = array('id' => '||'.$customers['customers_id']); 
    } 

    return $customers_array; 
    } 

plase需要帮助!谢谢!

+0

echo $ db_values并显示结果。另外,提供tep_db_query – phpmeh

+0

我认为问题在循环结束}把它放在下面,如果条件 –

回答

2

这是因为Insert +值在数据库中插入一行。 (您可以使用插入与SELECT查询插入多行使用插入命令,但这不是你的情况,因为我可以看到)。 因此,您应该提供包含多个插入命令(每个客户的插入命令)的脚本,以便将多行插入到数据库中。

+0

哈,我错过了他们关闭他们的循环。我认为他们仍在循环。 – phpmeh