Вставьте несколько строк в таблицу с помощью PHP ⇐ Php
-
Anonymous
Вставьте несколько строк в таблицу с помощью PHP
I am trying to insert multiple rows into SQL server DB using PHP and HTML from. I know basic PHP and searched many examples on different forums and created one script however it doesn't seem working. Can anybody help with this. Here is my script:
public function insert_corporate($customer_id, $selected_countries) { $values = array(); if (!is_array($selected_countries)) { // Suponiendo que $selected_countries es una lista de países separados por coma, la convertimos en un array $countries = explode(',', $selected_countries); } else { $countries = $selected_countries; } $sql = "INSERT INTO [dbo].[CORPORATE] ([CUSTOMER_ID], [COUNTRY_ID]) VALUES "; foreach ($countries as $country) { $values[] = "('$customer_id', '$country')"; } $sql .= implode(', ', $values); if (!$this->db->query($sql)) { return $error = 1;`your text } else { return $error = 0; } }
Источник: https://stackoverflow.com/questions/780 ... -using-php
I am trying to insert multiple rows into SQL server DB using PHP and HTML from. I know basic PHP and searched many examples on different forums and created one script however it doesn't seem working. Can anybody help with this. Here is my script:
public function insert_corporate($customer_id, $selected_countries) { $values = array(); if (!is_array($selected_countries)) { // Suponiendo que $selected_countries es una lista de países separados por coma, la convertimos en un array $countries = explode(',', $selected_countries); } else { $countries = $selected_countries; } $sql = "INSERT INTO [dbo].[CORPORATE] ([CUSTOMER_ID], [COUNTRY_ID]) VALUES "; foreach ($countries as $country) { $values[] = "('$customer_id', '$country')"; } $sql .= implode(', ', $values); if (!$this->db->query($sql)) { return $error = 1;`your text } else { return $error = 0; } }
Источник: https://stackoverflow.com/questions/780 ... -using-php