js_bbs.php(放在根目录下)内容
require("bbs/config.inc.php");
//连接,选择数据库
$link=mysql_connect($dbhost,$dbuser,$dbpw)ordie('Couldnotconnect:'.mysql_error());
mysql_select_db($dbname)ordie("Couldnotelectdatabase");
$fid=$_GET["fid"];
//截取字符长度
$length=36;
//防止中文乱码
mysql_query("setnames'gb2312'");
//执行SQL查询
$query="SELECTtid,subjectFROMcdb_threadswherefid='$fid'orderbylastpostdescLIMIT10";
$result=mysql_query($query)ordie("Queryfailed:".mysql_error());
//用HTML显示结果
while($myrow=mysql_fetch_row($result))
{
printf("document.writeln("
}
//释放结果集
mysql_free_result($result);
//关闭连接
mysql_close($link);
//截取字符函数
functioncutstr($string,$length,$dot='...'){
$strcut='';
for($i=0;$i<$length-strlen($dot)-1;$i++){
$strcut.=ord($string[$i])>127?$string[$i].$string[++$i]:$string[$i];
}
return$strcut.$dot;
}
?>