gpt4 book ai didi

php - MySQL插入查询一次插入多条记录

转载 作者:行者123 更新时间:2023-11-29 08:39:56 26 4
gpt4 key购买 nike

我的项目中有以下代码:

$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 条记录:一条记录​​包含所有正确值,其余 4 条记录包含空值。

开始时间由用户输入,结束时间根据开始时间计算。

插入表格后看起来像这样:

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

关于php - MySQL插入查询一次插入多条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14119182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com