海河写的 Discuz论坛帖子调用js的php代码
调用代码
<scriptlanguage="javascript"src="js_bbs.PHP?fid=1"> js_bbs.PHP(放在根目录下)内容
<?PHP
require("bbs/config.inc.PHP");
//连接,选择数据库
$link=@R_502_198@connect($dbhost,$dbuser,$dbpw)ordie('Couldnotconnect:'.@R502_198@error());
@R502_198@_select_db($dbname)ordie("Couldnotelectdatabase"); $fid=$_GET["fid"];
//截取字符长度
$length=36;
//防止中文乱码
@R_502_198@_query("setnames'gb2312'");
//执行SQL查询
$query="SELECTtid,subjectFROMcdbthreadswherefid='$fid'orderbylastpostdescLIMIT10";
$result=@R502_198@_query($query)ordie("QueryFailed:".@R_502_198@_error());
//用HTML显示结果
while($myrow=@R_502_198@_fetch_row($result))
{
printf("document.writeln(\"
<ahref=\\"bbs/viewthread.PHP?tid=%s&extra=page=1\\"target=\\"blank\\">%s\");\n",$myrow[0],cutstr($myrow[1],$length,".."));
}
//释放结果集
@R502_198@_free_result($result);
//关闭连接
@R_502_198@_close($link); //截取字符函数
functioncutstr($string,$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;
}
?>