У меня есть таблица обменных курсов, которую я хочу вставить для более чем одной страны.Как вставить несколько строк в один submit на codeigniter
это моя форма
<? form_open_multipart('exchange/create')
?>
<input type="text" name="user[0][ExchangeRateDate]"/>
<input type="text" name="user[0][CountryId]"/>
<input type="text" name="user[0][CashSelling]"/>
<input type="text" name="user[0][CashBuying]"/>
<input type="text" name="user[0][TransferSelling]"/>
<input type="text" name="user[0][TransferBuying]"/>
<input type="text" name="user[0][InsertDate]"/>
<input type="text" name="user[0][Status]"/>
<input type="text" name="user[1][ExchangeRateDate]"/>
<input type="text" name="user[1][CountryId]"/>
<input type="text" name="user[1][CashSelling]"/>
<input type="text" name="user[1][CashBuying]"/>
<input type="text" name="user[1][TransferSelling]"/>
<input type="text" name="user[1][TransferBuying]"/>
<input type="text" name="user[1][InsertDate]"/>
<input type="text" name="user[1][Status]"/>
<input type="submit" value="insert exchange" class="btn"/>
</form>
ее является модель код для текущей формы
public function set_exchange() {
$data = array('ExchangeRateDate' => $this -> input -> post('ExchangeRateDate'),
'CountryId' => $this -> input -> post('CountryId'),
'CashSelling' => $this -> input -> post('CashSelling'),
'CashBuying' => $this -> input -> post('CashBuying'),
'TransferSelling' => $this -> input -> post('TransferSelling'),
'TransferBuying' => $this -> input -> post('TransferBuying'),
'InsertDate' => $this -> input -> post('InsertDate'),
'Status' => $this -> input -> post('Status'));
return $this -> db -> insert('exchange_rate', $data);
}
и в конце концов, это Controller кодовая
public function create() {
$this -> load -> helper('form');
$this -> load -> library('form_validation');
$data['title'] = 'Create a news exchange rate';
$this -> form_validation -> set_rules('ExchangeRateDate', 'ExchangeRateDate', 'required');
$this -> form_validation -> set_rules('CountryId', 'CountryId', 'required');
$this -> form_validation -> set_rules('CashSelling', 'CashSelling', 'required');
$this -> form_validation -> set_rules('CashBuying', 'CashBuying', 'required');
$this -> form_validation -> set_rules('TransferSelling', 'TransferSelling', 'required');
$this -> form_validation -> set_rules('TransferBuying', 'TransferBuying', 'required');
$this -> form_validation -> set_rules('InsertDate', 'InsertDate', 'required');
$this -> form_validation -> set_rules('Status', 'Status', 'required');
$this -> all -> set_exchange();
$this -> load -> view('admin/exchange/create');
}
структура таблицы
ExchangeRateId
ExchangeRateDate
CountryId
CashSelling
CashBuying
TransferSelling
TransferBuying
InsertDate
Status
идея все работает отлично вставить новую строку данных идет в моей базе данных, но здесь я хочу, чтобы вставить более одного ряда в то время только ID не дублировать, а другие являются, так как моей формой я использую от другого застрявшего переполнения, но он не работает
поделиться своими знаниями
рег ОРДС заранее ......
Можете ли вы поделиться тем, что выбирает/вставляет вашу модель? Я имею в виду включить профилировщик (в конструкторе '$ this-> output-> enable_profiler (TRUE);') спасибо. Взгляните на пакетную вставку в этом справочном руководстве http://ellislab.com/codeigniter/user-guide/database/active_record.html # insert И в конце концов я не вижу вопросительного знака в вашем вопросе :) – Kyslik
@ Kyslik, да, ваше право mvc отлично работает, но вопрос в том, что я хочу вставить более одной строки, те же имена компланов, желаю, чтобы я мог бы очистить мой вопрос. –
Пожалуйста, сделайте небольшой пример с (2 столбцами) в комментариях, чего вы пытаетесь достичь. скажем, у нас есть структура таблицы следующим образом: 'id' | 'name' после отправки формы есть два набора данных (для' user [0] 'и для' user [1] 'right? – Kyslik