emlog文章GID斷號自動補入

EMLOG在刪除文章后GID就會斷掉,現在只需要簡單修改一下代碼,后面新增文章的時候就會優先選擇斷掉的文章ID。

路徑在include/model/log_model.php

原始代碼如下:

/**
* 添加文章、頁面
*
* @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;
}
修改為以下代碼:
/**
* 添加文章、頁面
*
* @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;
}
這樣就可以解決emlog文章斷ID的問題了!

轉載請注明出處 AE博客|墨淵 ? emlog文章GID斷號自動補入

相關推薦

發表評論

路人甲

網友評論(0)