簡體   English   中英

MySQL插入查詢一次插入多個記錄

[英]MySQL insert query inserting more than one record at a time

我在我的項目中有以下代碼:

$start_time = $this->input->post("start_time");
$a          = explode(":",$start_time);
$start_sec  = ($a[0]*3600)+($a[1]*60);
$end_sec    = $start_sec+5400;
$m          = ($end_sec/60);
$hrs        = (int)($m/60);
$mins       = ($m%60);
$sec        = "00";
$end_time   = $hrs.":".$mins.":".$sec;
$start_time .= ":".$sec;


$tablearr=array(
  "rest_id"        => $info['rest_id'],
  "rest_sec_id"    => $info['rest_sec_id'],
  "book_date"      => $this->input->post("date"),
  "book_start_time"=> $this->input->post("start_time"),
  "book_end_time"  => $end_time,
  "book_special"   => $this->input->post("purpose"),
  "book_cuisine"   => $this->input->post("cuisine"),
  "book_no_person" => $this->input->post("no_person"),
  "user_id"        => $this->session->userdata('member_id'),
  "book_is_menu"   => $this->input->post("menu"),
  "table_reserved" => $info['table_reserved']
);

$this->db->insert("b_rest_book",$tablearr);

這應該插入“預訂”的單個記錄。 但是在查詢中插入了5條記錄:一條記錄​​包含所有正確的值,另外四條記錄具有空值。

用戶輸入開始時間,並根據開始時間計算結束時間。

插入表后看起來像這樣:

book_id     rest_id     rest_sec_id     book_date   book_start_time     book_end_time   book_special    book_cuisine    book_no_person  user_id     book_is_menu    table_reserved  special_request

1   1   2   2012-12-23  07:00:00    08:30:00    2   2   2   2   No  1 

2   1   0   0000-00-00  00:00:00    01:30:00    0   0   0   2       1 

3   1   0   0000-00-00  00:00:00    01:30:00    0   0   0   2       1 

4   1   0   0000-00-00  00:00:00    01:30:00    0   0   0   2       1    
5   1   0   0000-00-00  00:00:00    01:30:00    0   0   0   

究竟出了什么問題?

嘗試這個:

if($info['rest_sec_id'] != 0)
{
   $this->db->insert("b_rest_book",$tablearr);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM