欢迎访问 舍力博客(www.shuyong.net)
/** * 添加文章、页面 * * @param array $logData * @return int */ function addlog($logData) { $kItem = array(); $dItem = array(); foreach ($logData as $key => $data) { $kItem[] = $key; $dItem[] = $data; } $field = implode(',', $kItem); $values = "'" . implode("','", $dItem) . "'"; $this->db->query("INSERT INTO " . DB_PREFIX . "blog ($field) VALUES ($values)"); $logid = $this->db->insert_id(); return $logid; }修改为:
function addlog($logData) { $kItem = array(); $dItem = array(); foreach ($logData as $key => $data) { $kItem[] = $key; $dItem[] = $data; } $field = implode(',', $kItem); $values = "'" . implode("','", $dItem) . "'"; $gidarr[0]='0'; $res = $this->db->query("SELECT gid From " . DB_PREFIX . "blog ORDER BY gid ASC"); while ($row = $this->db->fetch_array($res)) { $gidarr[] = $row['gid']; } foreach($gidarr as $key=>$val){ if($key!=$val){ $field = 'gid,'.$field; $values = "'".$key."',".$values; break; } } $this->db->query("INSERT INTO " . DB_PREFIX . "blog ($field) VALUES ($values)"); $logid = $this->db->insert_id(); return $logid; }通过改变是否需要插入语句添加gid和gid值,来自增或者插入。 假如你有多篇文章删除,添加一篇的话,只有从开始的断号,慢慢补全断号。
留言/评论:◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。