php - 尝试在 php + mysql 中保存表中的多行时遇到麻烦

标签 php mysql rows

您好,我在尝试使用客户表 ID 保存表“通知”中的多行时遇到了麻烦,但它只保存了一行,这是我的代码:

  $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;
  }

请帮忙!!!谢谢!

最佳答案

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

关于php - 尝试在 php + mysql 中保存表中的多行时遇到麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8292429/

相关文章:

python - 如何比较两个数据框并使用 python 获取不匹配的行?

php - 如何防止用户通过 ajax 请求中的 Firebug 更改变量

php - 如何首先显示最新上传的图像? (PHP+CSS)

php - 使用PHP从数据库中检索多个图像

javascript - 使用 AdWords 脚本/Javascript 在电子表格的不同行上打印数组中的对象

mysql - 如何在 MySQL 中将行更改为列

php - Doctrine QueryBuilder 未定义方法 getQuery()

PHP 电子邮件 header - 传送选项

java - SQL Error : 1054, SQLState: 42S22 Unknown column in 'field list' 错误 Java Spring Boot Mysql 错误

mysql - Laravel Supervisord 数据库死锁