调用代码
<script language="javascript" src="js_bbs.php?fid=1"></script>
js_bbs.php(放在根目录下) 内容
<?php
require ("bbs/config.inc.php");
//连接,选择数据库
$link = mysql_connect( $dbhost,$dbuser,$dbpw) or die('Could not connect:'.mysql_error());
mysql_select_db($dbname) or die("Could not elect database");
$fid=$_GET["fid"];
//截取字符长度
$length=36;
//防止中文乱码
mysql_query("set names 'gb2312'");
//执行SQL查询
$query = "SELECT tid,subject FROM cdb_threads where fid='$fid' order by lastpost desc LIMIT 10";
$result = mysql_query($query) or die("Query failed: ".mysql_error());
// 用 HTML显示结果
while ($myrow = mysql_fetch_row($result))
{
printf("document.writeln(\"<li><a href=\\\"bbs/viewthread.php?tid=%s&extra=page=1\\\ " target=\\\"_blank\\\">%s</a></li>\");\n", $myrow[0],cutstr($myrow[1], $length,".."));
}
// 释放结果集
mysql_free_result($result);
//关闭连接
mysql_close($link);
//截取字符函数
function cutstr($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;
}
?>
<script language="javascript" src="js_bbs.php?fid=1"></script>
js_bbs.php(放在根目录下) 内容
<?php
require ("bbs/config.inc.php");
//连接,选择数据库
$link = mysql_connect( $dbhost,$dbuser,$dbpw) or die('Could not connect:'.mysql_error());
mysql_select_db($dbname) or die("Could not elect database");
$fid=$_GET["fid"];
//截取字符长度
$length=36;
//防止中文乱码
mysql_query("set names 'gb2312'");
//执行SQL查询
$query = "SELECT tid,subject FROM cdb_threads where fid='$fid' order by lastpost desc LIMIT 10";
$result = mysql_query($query) or die("Query failed: ".mysql_error());
// 用 HTML显示结果
while ($myrow = mysql_fetch_row($result))
{
printf("document.writeln(\"<li><a href=\\\"bbs/viewthread.php?tid=%s&extra=page=1\\\ " target=\\\"_blank\\\">%s</a></li>\");\n", $myrow[0],cutstr($myrow[1], $length,".."));
}
// 释放结果集
mysql_free_result($result);
//关闭连接
mysql_close($link);
//截取字符函数
function cutstr($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;
}
?>
版权声明:
本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。