<?php
$dbhost='127.0.0.1';
$dbname='tp';
$dbuser='root';
$dbpass='root';
date_default_timezone_set('PRC');
try{$pdo=new PDO('mysql:host='.$dbhost.';dbname='.$dbname,$dbuser,$dbpass);}catch(Exception $e){die('sqlsb');}
$rt=$pdo->query('SELECT * FROM `typecho_contents` LIMIT 20')->fetchAll(PDO::FETCH_ASSOC);
foreach($rt as $ttt){
$rr=$pdo->query('SELECT * FROM `typecho_comments` WHERE `cid`='.$ttt['cid'].' ORDER BY `coid` ASC')->fetchAll(PDO::FETCH_ASSOC);
$txt='
<br />
<div class="nima_comments">
';
foreach($rr as $rrr){
$txt.='<hr />
<div class="nima_comment" id="nima_comment_'.$rrr['coid'].'">
<span class="nima_comment_user">'.(empty($rrr['url'])?$rrr['author']:'<a href="'.$rrr['url'].'" target="_blank" rel="nofollow">'.$rrr['author'].'</a>').'</span>
'.(($rrr['created']==28800)?'':'在
<span class="nima_comment_time">'.date('Y/m/d H:i:s',$rrr['created']).'</span>
').(empty($rrr['parent'])?'评论':'<a href="#nima_comment_'.$rrr['parent'].'">回应</a>').':
<br />
<span class="nima_comment_text">'.$rrr['text'].'</span>
</div>
';
}
$txt.='</div>
';
$ttt['text'].=$txt;
$pdo->exec('UPDATE `typecho_contents` SET `text`="'.addslashes($ttt['text']).'" WHERE `cid`='.$ttt['cid']);
}
?>
仅供参考