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]";
I think you understand what i want
I cant include header.php after the query, because i wont be connected to mysql
waht do you suggest other than having the connection snippet on every page
What do I suggest? A MVC (Model-View-Controller) Framework like Kohana. If you don’t want to go that route, break your connection off into its own file:
Note here how I have a
$pagearray of data. This will be helpful when debugging later rather than having several independent variables. With an array of page data, I can quickly see all of the information laid out for any given page:Determining your title should be done within
page-data.php, rather than on your page: