What should I use for this?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

What should I use for this?

Post by Jim »

I want to create a code for titles which says "if this page is called "thisfile.html" then $title="Whatever Description Fits"

Any ideas?

Thanks!
Peter
Forum Commoner
Posts: 28
Joined: Mon Jun 10, 2002 12:40 am
Location: Brisbane, Australia

Post by Peter »

Try this....

Code: Select all

<?php

switch($HTTP_SERVER_VARS&#1111;'PHP_SELF'])&#123;
    case "/whatever.html":
        $title = "hey!";
        break;
    case "/anotherpage.html":
        $title = "page #2";
        break;
    case "/index.html":
        $title = "Index";
        break;
&#125;

?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

An alternative is to use arrays:

Code: Select all

$titles = array(
    'whatever.html' => 'hey!',
    'anotherpage.html' => 'page #2',
    'index.html' => 'index'
);
So when you want to insert the title:

Code: Select all

echo '<title>'.$titles&#1111;$page].'</title>';
Or you can put all the information about the page in a database...

Mac
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

It's a bit over the top but on some of my larger sites I like to keep all of that stuff in a mysql database and pull it all out before constructing the page. A bit of code for you as an example taken straight from one of my sites
<?php
if ($page == "") {
$page='home';}
include "connection.php";
$initialquery = "SELECT * FROM tblpage AS t2 ";
$queryconditions = "WHERE t2.gpName LIKE \"".$page."\" ";
$orderresults = "ORDER BY t2.gpName";
$getresults = $initialquery." ".$queryconditions." ".$orderresults;
$result = mysql_query($getresults, $db_connection);
$num_results = mysql_num_rows($result);
if ($num_results == "") {
echo "There has been an error in the site please try and refresh your browser, if the problem persists please contact customer services";
}else {
$info = mysql_fetch_array($result);
}
//Set values from those in the database
$Pagecode = stripslashes($info["gpPage"]);
$PageName = stripslashes($info["gpName"]);
$Title = stripslashes($info["gpTitle"]);
$Keywords = stripslashes($info["gpKeywords"]);
$Desc = stripslashes($info["gpDescription"]);
$Navgroup = stripslashes($info["gpNavgroup"]);
$Navlinkname = stripslashes($info["gpNavlinkname"]);
$Header = stripslashes($info["gpHeader"]);
$Main = stripslashes($info["gpMain"]);
$Footer = stripslashes($info["gpFooter"]);
It's a bit server heavy to do this sort of thing but I like having good easy access to all of these things so I can change them to keep up with whatever the current thinking on search engine optimisation is. :wink: I run this at the top of the page before everything except cookies.
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

That could come in handy for template design.
I think I did something very similar.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

It's not the newest bit of code I've done and I'd advice you edit out lots of " and put in some ' in their place, no point making the server work too hard. :wink:
Post Reply