Typecho 文章CID 和 分类标签MID 自动排序

Typecho 文章CID 和 分类标签MID 自动排序

Fate
2020-05-31 / 0 评论 / 968 阅读 / 正在检测是否收录...

注意事项

使用PHP7.0以下运行

解决CID不连续PHP

<?php
$hostname_blog = "localhost";
$database_blog = "数据库名";
$username_blog = "数据库用户名";
$password_blog = "数据库密码";
$blog = mysql_pconnect($hostname_blog, $username_blog, $password_blog) or trigger_error(mysql_error(),E_USER_ERROR);
$no = 1;
function change_id($cid)
{
    global $no;
    $sql = 'update typecho_contents set cid = ' . $no . ' where cid = ' . $cid;
    mysql_query($sql);
    $sql = 'update typecho_relationships set cid = ' . $no . ' where cid = ' . $cid;
    mysql_query($sql);
    $sql = 'update typecho_comments set cid = ' . $no . ' where cid = ' . $cid;
    mysql_query($sql);
    $no = $no + 1;
}
mysql_select_db($database_blog, $blog);
$query_postRecord = "SELECT cid FROM typecho_contents ORDER BY cid ASC";
$all_postRecord = mysql_query($query_postRecord);
$row_postRecord = mysql_fetch_assoc($all_postRecord);
do {
    change_id( $row_postRecord['cid'] );
} while ($row_postRecord = mysql_fetch_assoc($all_postRecord));
mysql_query('alter table typecho_contents AUTO_INCREMENT = ' . $no);
echo 'OK';
?>

解决MID不连续PHP

<?php
$hostname_blog = "localhost";
$database_blog = "数据库名";
$username_blog = "数据库用户名";
$password_blog = "数据库密码";
$blog = mysql_pconnect($hostname_blog, $username_blog, $password_blog) or trigger_error(mysql_error(),E_USER_ERROR); 
$no = 1;
function change_id($mid)
{
    global $no; 
    $sql = 'update typecho_metas set mid = ' . $no . ' where mid = ' . $mid;
    mysql_query($sql);
    $sql = 'update typecho_relationships set mid = ' . $no . ' where mid = ' . $mid;
    mysql_query($sql);
    $no = $no + 1;
}
mysql_select_db($database_blog, $blog);
$query_postRecord = "SELECT mid FROM typecho_metas ORDER BY mid ASC";
$all_postRecord = mysql_query($query_postRecord);
$row_postRecord = mysql_fetch_assoc($all_postRecord);
do {
    change_id( $row_postRecord['mid'] );    
} while ($row_postRecord = mysql_fetch_assoc($all_postRecord));
mysql_query('alter table typecho_metas AUTO_INCREMENT = ' . $no);
echo 'OK';
?>
0

评论

博主关闭了所有页面的评论