我已经使用PHP OOP制作了CMS,在此CMS中,网站的管理员可以添加,编辑和删除其网站的菜单导航。因此,为了插入新的菜单导航,我编写了这个类:
<?php
class Navigation
{
private $db;
public function __construct()
{
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function NewMenu($menu_name,$menu_numbers)
{
if(!empty($menu_name)&&!empty($menu_numbers))
{
$menu = $this->db->prepare("SELECT menu_name FROM menu_nav WHERE menu_name = ?");
$menu->bindParam(1,$menu_name);
$menu->execute();
if($menu->rowCount() == 1)
{
$notice['menu_exists'] = "Your menu already exists";
// header("Location: addnewmenu.php?menu_name=false");
}else{
$ins = $this->db->prepare("INSERT INTO menu_nav (menu_name, menu_items) VALUES (?, ?)");
$ins->bindParam(1,$menu_name);
$ins->bindParam(2,$menu_numbers);
$ins->execute();
$notice['menu_added'] = "Menu added successfully";
// header("Location: addnewmenu.php?menu_name=true");
}
}
}
}
它工作得很完美,它正确地在表中添加了一个新行,但我想要做的是将表的 id (这是唯一的)设置为0以上的数字而不是0例如,您可以在此图片中看到我的 right_menu 的ID设置为0.
所以我必须手动将其更改为1。我需要一些自动执行该操作的代码,并从1开始设置导航的ID!
那我怎么能这样做呢?
答案 0 :(得分:2)
只需将auto_increment添加到您的ID列
即可<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div class="panel-body">
<div class="input-group control-groups after-add-more-inputs">
<input type="text" name="addmore[]" class="form-control" style="width:30%;">
<input type="text" name="addmore[]" class="form-control" style="width:30%;">
<input type="text" name="addmore[]" class="form-control" style="width:30%;">
</div>
<br />
<div class="add-more-inputs">
<a href="#">Add</a>
</div>
<!-- Copy Fields -->
<div class="copy-field hide">
<div class="control-groups input-group" style="margin-top:10px">
<input type="text" name="addmore[]" class="form-control" style="width:30%;">
<input type="text" name="addmore[]" class="form-control" style="width:30%;">
<input type="text" name="addmore[]" class="form-control" style="width:30%;">
<div class="remove">
<a href="#"> Remove</a>
</div>
</div>
</div>
</div>