【EMLOG教程】删除文章后补全文章ID方法

1、打开程序路径: include/model/log_model.php  (16行左右)
原代码:
/**
* 添加文章、页面
*
* @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;
}
2、修改为以下代码即可。
/**
* 添加文章、页面
*
* @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) . "'";
    $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;
}

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧