的header.php動態標題最好的方式?
<?php
$conn = mysql_connect('localhost', '-', '-');
@mysql_select_db('accmaker', $conn) or die("Unable to select database");
?>
<html>
<head>
<title>Mysite.com - <?php isset($pageTitle) ? $pageTitle : 'Home'; ?></title>
</head>
<body>
profile.php
require 'header.php';
$q = mysql_query("SELECT * FROM users WHERE username = '$username'");
$r = mysql_fetch_assoc($q);
$pageTitle = "Profile of $r[username]";
我想你明白我想要什麼
我不能包括的header.php查詢後,因爲我不會連接到MySQL
你是否建議除了在每一頁上都有連接片段
呀,勢必要找到一個很好的MVC框架......但如果你堅持工作的遺留系統上......嗯,你只是運氣不好的時候。 – 2010-01-08 15:22:40
要添加的另一件事(框架已經這樣做):緩衝你的輸出。所以,腳本在輸出開始之前結束。 因此,您不會有0.5s或更多的數據庫連接打開客戶端需要下載頁面。 – Arkh 2010-01-08 15:53:48