我有以下内容:
模型文件
$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
?
最佳答案
你可以使用子查询:
$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)');
关于mysql - 如何在opencart的mysql中插入最大值加一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763032/