Haihe wrote Discuz forum post call js PHP code _php Tips

Source: Internet
Author: User
Calling code
<script language= "javascript" src= "js_bbs.php?fid=1" ></script>

Js_bbs.php (put in root directory) content


<?php
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
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" (\ "<li><a href=\\\" bbs/viewthread.php?tid=%s&extra=page=1\\\ "target=\\\" _ blank\\\ ">%s</a></li>\"); \ n ", $myrow [0],cutstr ($myrow [1], $length," ... "));
}
Releasing the result set
Mysql_free_result ($result);
Close connection
Mysql_close ($link);

Intercepting 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;
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.