调用代码
<scriptlanguage="javascript"src="js_bbs.PHP?fid=1"> js_bbs.PHP(放在根目录下)内容
<?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,$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;
}
?>
原文链接:https://www.f2er.com/php/29850.html