如何在opencart中的mysql中插入最大值加1

时间:2018-02-13 09:08:44

标签: mysql opencart

我有以下内容:

模型文件

$max = $this->db->query("SELECT MAX( sort ) FROM lc_menu");
print_r($max);

印刷值

stdClass Object ( [num_rows] => 1 [row] => Array ( [MAX( sort )] => 64 )
[rows] => Array ( [0] => Array ( [MAX( sort )] => 64 ) ) )

如何在MySQL查询中插入max+1

1 个答案:

答案 0 :(得分:0)

您可以使用子查询:

$this->db->query('INSERT INTO ' . DB_PREFIX . ' menu SET
menuname = "$this->db->escape($data['menuname'])",
start_date = "$this->db->escape($data['start_date'])",
start_time = "$this->db->escape($data['start_time'])",
end_date = "$this->db->escape($data['end_date'])",
end_time = "$this->db->escape($data['end_time'])",
link_value = "$this->db->escape($data['link_value'])",
link = "$this->db->escape($alpha['link'])",
sort = ((SELECT MAX(sort) FROM lc_menu) + 1)');