Home >Backend Development >PHP Tutorial >Discuz forum post written by Haihe calls php code of js_PHP tutorial

Discuz forum post written by Haihe calls php code of js_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:54:33910browse

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 the results in HTML
while ($myrow = mysql_fetch_row($result))
{
printf("document.writeln("

  • %s
  • ");n", $myrow[0], cutstr($myrow[1], $length,".."));
    }
    // Release the result set
    mysql_free_result($result);
    //Close the connection
    mysql_close ($link);

    //Intercept character function
    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;
    }
    ?>

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318445.htmlTechArticleCalling code scriptlanguage="javascript"src="js_bbs.php?fid=1"/script js_bbs.php( Put it in the root directory) content?php require("bbs/config.inc.php"); //Connect, select database $link=m...
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn