PDA

View Full Version : Simple(I hope) PHP script problem.



fileserverdirect
05-29-2007, 07:55 PM
Hi everyone,

I am writing a page in PHP, and I wanted a simple titlebar maker. It take a command "yes" or "no" after each variable. Then the if command makes each title into the variable "$title". the $title in then later put into the html tag, <title>. Here is the code:



<?php
//title \|/Select yes only once

$general = "yes"
$games = "no"
$web_devop = "no"
$websites = "no"
$advert = "no"
$news = "no"
//page title

$pagetitle = "Home" //Enter the page title here

//DO NOT EDIT BELOW THIS POINT
$begintitle = "My Comany Name&trade; -- "
$gentitle = "MCN General"
$gamestitle = "MCN Games"
$web_devoptitle = "MCN Web Devopment"
$websitestitle = "MCN Websites"
$adverttitle = "MCN Adverts"
$newstitle = "MCN News"



//title printing

if ($general = "yes") {
$title = "$begintitle $pagetitle &bull; $gentitle";
};

elseif ($games = "yes") {
$title = "$begintitle $pagetitle &bull; $gamestitle";
};

elseif ($web_devop = "yes") {
$title = "$begintitle $pagetitle &bull; $web_devoptitle";
};

elseif ($websites = "yes") {
$title = "$begintitle $pagetitle &bull; $websitestitle";
};

elseif ($advert = "yes") {
$title = "$begintitle $pagetitle &bull; $adverttitle";
};

elseif ($news = "yes") {
$title = "$begintitle $pagetitle &bull; $newstitle";
};

else {
$title = "My Company Name";
};


//HTML/////////////////////////////////////////////PART 04
?>

<html>
<head>
<title>
<?php
$title
?>
</title>
</head>
<body>
Test
</body>
</html>
NOTE:
I changed the name of my company to "My Company Name" and "MCN" for short.
Let me answer some questions you might ask:
No error messages come up when uploaded
Uploaded to a PHP compatable server
Uploaded in ASCII format
Nothing showed up when page was loaded, not even the HTML code.
I will add a "thanks" to anyone whom is helpful to solving this script problem
Thanks!

mbrodin
05-29-2007, 08:15 PM
Hi, fileserverdirect!

In every If-statement you have add only one "=",



if ($general = "yes")


add to this instead:


if ($general == "yes")


OBS!! - REMOVE ALL ; AFTER }; AND ADD THEM AFTER
$general = "yes" Add here-> ;

Here are the code:

<?php
//title \|/Select yes only once

$general = "yes";
$games = "no";
$web_devop = "no";
$websites = "no";
$advert = "no";
$news = "no";
//page title

$pagetitle = "Home"; //Enter the page title here

//DO NOT EDIT BELOW THIS POINT
$begintitle = "My Comany Name&trade; -- ";
$gentitle = "MCN General";
$gamestitle = "MCN Games";
$web_devoptitle = "MCN Web Development";
$websitestitle = "MCN Websites";
$adverttitle = "MCN Adverts";
$newstitle = "MCN News";



//title printing

if ($general == "yes") {
$title = "$begintitle $pagetitle &bull; $gentitle";
}

elseif ($games == "yes") {
$title = "$begintitle $pagetitle &bull; $gamestitle";
}

elseif ($web_devop == "yes") {
$title = "$begintitle $pagetitle &bull; $web_devoptitle";
}

elseif ($websites == "yes") {
$title = "$begintitle $pagetitle &bull; $websitestitle";
}

elseif ($advert == "yes") {
$title = "$begintitle $pagetitle &bull; $adverttitle";
}

elseif ($news == "yes") {
$title = "$begintitle $pagetitle &bull; $newstitle";
}

else {
$title = "My Company Name";
}


//HTML/////////////////////////////////////////////PART 04
?>

<html>
<head>
<title>
<?php echo $title?>
</title>
</head>
<body>
Test
</body>
</html>


I hopes this was helpfull?

Best regards,
mbrodin

mbrodin
05-29-2007, 08:40 PM
Hi again!

You can also do this way:


<?php
//title \|/Select yes only once

$isWhat = "games";

$beginTitle = "My Comany Name&trade; --";
$pageTitle = "Home"; // Enter the page title here

// Title printing
switch( $isWhat )
{

case 'news':
$title = $beginTitle . " " . $pageTitle . " &bull; MCN News";
break;

case 'advert':
$title = $beginTitle . " " . $pageTitle . " &bull; MCN Adverts";
break;

case 'websites':
$title = $beginTitle . " " . $pageTitle . " &bull; MCN Websites";
break;

case 'web_develop':
$title = $beginTitle . " " . $pageTitle . " &bull; MCN Web Development";
break;

case 'games':
$title = $beginTitle . " " . $pageTitle . " &bull; MCN Games";
break;

case 'general':
$title = $beginTitle . " " . $pageTitle . " &bull; MCN General";
break;

default:
$title = "My Company Name";
break;

}

//HTML/////////////////////////////////////////////PART 04
?>

<html>
<head>
<title>
<?php echo $title?>
</title>
</head>
<body>
Test
</body>
</html>

Best regards,
mbrodin

fileserverdirect
05-29-2007, 08:50 PM
Yes, thanks... the html code appears! The title bar doesn't, though. I think maybe that you should use some sort of do "document.title" thing, I tryed it and this doesn't work:


if ($general == "yes") {
document.title = "$begintitle $pagetitle &bull; $gentitle";
}

Is there any other way to target the title?

mbrodin
05-29-2007, 09:00 PM
Yes, thanks... the html code appears! The title bar doesn't, though. I think maybe that you should use some sort of do "document.title" thing, I tryed it and this doesn't work:


if ($general == "yes") {
document.title = "$begintitle $pagetitle &bull; $gentitle";
}

Is there any other way to target the title?

Hi!

The problem in "title" is that you have


if ($general == "yes") {
document.title = "$begintitle $pagetitle &bull; $gentitle";
}


change to this:


if ($general == "yes") {
$title = "$begintitle $pagetitle &bull; $gentitle";
}


;)

Best regards,
mbrodin

fileserverdirect
05-29-2007, 09:30 PM
Thanks, but my question was like this:
Forget the "<title><?php echo $title ?></title>"
Is there a way to DIRECTLY insert the title in to the document? I have seen this before in javascript.
I used your first post, or the original code, just beacuse :)
Thanks

mbrodin
05-30-2007, 04:40 AM
Is there a way to DIRECTLY insert the title in to the document? I have seen this before in javascript.
I used your first post, or the original code, just beacuse :)
Thanks

Good morning!

Hm, I'm not quite sure what U mean, but what I think U mean there are no other way to do this because PHP is a server language and Javascript runs on the client and therefore it's possible for Javascript to use "document.title" while it's impossible for PHP.

Keep have a nice day!

Best regards,
mbrodin

djr33
05-30-2007, 05:12 AM
document.title in javascript is actually an object on the page.
That's like actually changing something real, like drawing on a piece of paper.

$title in PHP is just a variable, a value you can later do something with.
that's like saving some text in a word processor which you could later print onto a piece of paper.

fileserverdirect
05-30-2007, 11:11 PM
Thanks Guys! Evreything works, and I am happy, it's a good state of mind:)