Calling code
js_bbs.php (placed in the root directory) content
Require ("bbs/config.inc.php");
Connect, select Database
$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"];
Intercept character length
$length = 36;
Prevent Chinese garbled characters
mysql_query ("Set names ' gb2312 '");
Execute SQL query
$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 ());
Display results in HTML
while ($myrow = Mysql_fetch_row ($result))
{
printf ("Document.writeln (\")
%s\ ") \ n", $myrow [0],cutstr ($myrow [1], $length, "..."));
}
Releasing the result set
Mysql_free_result ($result);
Close connection
Mysql_close ($link);
Intercept character functions
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;
}
?>
The above describes the discuz! Haihe wrote the Discuz forum post called JS PHP code, including the discuz! aspects of the content, I hope that the PHP tutorial interested in a friend helpful.