Page 1 of 1
Header/footer design + <title></title>
Posted: Mon Jul 11, 2005 5:46 pm
by Jim_Bo
Hi,
Bit of a mental block at the moment and I need to sort this,
I am using require header/footer design with switch request to call the pages between. I cant figure out how to get the <title></title> for each page being displayed, I have the page names stored in db .. I am using <title><?php echo $pagename; ?></title> in the header page.
How or which is the best way to grab and display the title for each page?
Cheers
Posted: Mon Jul 11, 2005 6:00 pm
by Burrito
at some point you're going to have to identifiy the page, url var, static page var etc so it knows what to display. Because you're including "template" file for your header, you'll need to set the var above the include.
ex:
Code: Select all
$pageOn = "e;products"e;;
include("e;header.inc.php"e;);
then in your header page:
Code: Select all
$result = mysql_query("e;select title from pagetitles where page = '$pageOn'"e;);
edit: after looking at that, I asked myself, why, why oh why.
just set the page title with $pageOn and then echo it on the include, there's no need to yank stuff from the db...
Posted: Mon Jul 11, 2005 6:08 pm
by Jim_Bo
Hi,
Im still abit lost .. I tried by adding
$pagename = "About Us";
on the About Us page, but because the variable is set after
<title><?php echo $pagename; ?></title>
It doesnt work, how would it know that it is displaying the about us page to set the variable for it, as there are 20 or so pages?
Cheers
Posted: Mon Jul 11, 2005 6:13 pm
by Burrito
note the code I posted above.
you have to set the $pagename var above your include.
Posted: Mon Jul 11, 2005 6:22 pm
by Jim_Bo
Hi,
That I understand, but how does it know what page its on
$pageOn = "About Us";
$pageOn = "Silent Auction";
require "header.inc.php";
How does it know which page it is on to know what variable to fetch?
Dont know why, but I cant get my head around this

harder things I can seem to figure out
Cheers
Posted: Mon Jul 11, 2005 6:44 pm
by Burrito
you'd have to set it on each page. The alternative would be to use something like $_SERVER['PHP_SELF'] and based on the filename, you set the title that way...if you did that, then you might be better off going to the db for a page title that is associated with the file name.
Posted: Mon Jul 11, 2005 7:57 pm
by Jim_Bo
Hi,
I have stored the url and page title in the database ie
index.php?pages=about_us About Us
index.php?pages=auction Silent Auction
how do I go about calling the variable to the link for each page and also match the page title .. Obviously looping isnt going to work.
How do other people get around this, I assume the way I have made my template is commonly used.
Cheers
Posted: Mon Jul 11, 2005 8:10 pm
by Burrito
if you're using a url var then it makes it even easier.
just query the database for the page title based on the url var:
ex:
Code: Select all
$result = mysql_query("select pagetitle from pages where page = '".$_GET['pages']."'")
or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo "<title>".$row['pagetitle']."</title>";
Posted: Mon Jul 11, 2005 8:45 pm
by Jim_Bo
Hi,
I assume you mean something like:
Code: Select all
<?php
$result = mysql_query("select pagetitle from pages where url = '".$_GET['url']."'") or die(mysql_error());
$row = mysql_fetch_assoc($result);
?>
<title><?php echo $row['pagetitle']; ?></title>
That is relying on a match from the url that is held in the database correct?
How do I call the url from the database to begin with .. without having loads of querys
Code: Select all
<a href="../<?php echo $url; ?>">Rivers</a>
?
Cheers
Posted: Mon Jul 11, 2005 9:12 pm
by Burrito
no, your url var is pages, so that's why I used page = '".$_GET['pages']."' in the query string.
to answer your last question, you could popuplate those links with whatever variable type you want, db, session, static-page, url, form etc...
let's say my url looked like this:
http://www.mysite.com/page.php?var1=about_us.php
I could use that as my link on that page:
Code: Select all
echo "<a href=\"".$_GET['var1']."\">About Us</a>";
Posted: Mon Jul 11, 2005 10:16 pm
by Jim_Bo
Hi,
I parsed the record id in the url ..
Code: Select all
<a href="../index.php?pages=aboutus&id=<?php echo '1' ?>">About Us</a>
and matched it to the database id in thw query which works fine, I could just parse the page name thru the url as well but I guess that would look bad.
Is this a plausable way to do it?
I would have thought lots of people use the header/footer scenario, there for been a common way people would acheicve this.
The other thing I would like to acheive is to read the urls from the database rather than typing them in, how would one acheive this?
Cheers
Posted: Mon Jul 11, 2005 10:29 pm
by Burrito
we chatted on MSN and came up with something like this:
ßµяяiτö says:
id pagename pageurl pagetitle
1 about_us about_us.php About Us
2 contact_us contact_us.php Contact Us
ßµяяiτö says:
etc
ßµяяiτö says:
then you'd do this
ßµяяiτö says:
while($row = mysql_fetch_assoc($result)){
echo "<a href=\"".$row['pageurl']."\?pagename=".$row['pagename'].">".$row['pagetitle']."</a><br>";
}
ßµяяiτö says:
if you're doing it all through index.php, then just substitue that pageurl var with index.php
ßµяяiτö says:
then on each page (or in the header) check what the pagename is and include the appropriate title