首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

BBS 系統 PHP + MySQL 核心模組代碼片段(七)

     編輯:PHP 相關知識

BBS 前端互動與資料庫連線核心代碼

本文收錄 BBS 系統關鍵 JavaScript 與 PHP 模組片段,包含浮動選單定位、資料庫連線封裝。

1. 浮動選單定位 JavaScript (top.js)

function KB_keepItInIE(theName, theWantTop, theWantLeft) {
    theRealTop = parseInt(document.body.scrollTop);
    theTrueTop = theWantTop + theRealTop;
    document.all[theName].style.top = theTrueTop;
    theRealLeft = parseInt(document.body.scrollLeft);
    theTrueLeft = theWantLeft + theRealLeft;
    document.all[theName].style.left = theTrueLeft;
}

function KB_keepItInNN(theName, theWantX, theWantY) {
    theRealLay = document.layers[theName];
    theBadX = self.pageYOffset;
    theBadY = self.pageXOffset;
    theRealX = theBadX + theWantX;
    theRealY = theBadY + theWantY;
    theRealLay.moveTo(theRealY, theRealX);
}

IE4 = (document.all) ? 1 : 0;
NN4 = (document.layers) ? 1 : 0;
// setInterval 範例已註解

支援 IE4+ (document.all) 與 NN4 (document.layers) 雙模式,現代瀏覽器請改用 position: fixed CSS 實現。

2. 資料庫連線模組 (mysql.inc)

<?php
$link = mysql_pconnect("localhost", "xiaoyang", "xiaoyang") or die(mysql_error());
$link1 = mysql_select_db("database") or die(mysql_error());
?>

重要提醒:mysql_* 函式已於 PHP 7.0 移除,現代專案請改用 mysqli 或 PDO,並採用參數化查詢防範 SQL 注入。

3. 選單頁首片段 (menuhead.php)

<?php echo ""; ?>

疑為預留模板區塊,實際專案中通常包含導航列、使用者狀態等共用版頭內容。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved