2 Replies - 494 Views - Last Post: 27 September 2012 - 04:29 AM Rate Topic: -----

#1 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Back into PHP.

Posted 27 September 2012 - 04:22 AM

Hey guys, I've decided to get back into coding in PHP as it's been a good few years since I did any work in it. I had the idea of setting up a web page, and having it update the title. Like
Website - (Page name (Home/About/Contact))

So if I went to the "About Us" page, it would change the title to Website - About Us. But I'm having a bit of trouble with the variable, as it doesn't update no matter what I do/change. My simple file is below if anyone is able to help.
<html>
<head>
 <?php global $pageTitle; ?>
 <title><?php echo $pageTitle; ?></title>
</head>

<body bgcolor="black" />
 <?php
 
  echo("<center><a href=\"index.php\" /><font color=\"white\" />Home</font></a> &middot; <a href=\"?page=about\" /><font color=\"white\" />About us</font></a></center>");
  
  if (!isset($_GET['page'])) {
   $pageTitle = "Home";
   echo("Sup");
  } else {    
   $page = $_GET['page'];  
    switch($page) {
      case 'about':
	   $pageTitle = " - About Us";
	   echo("About");
       break;  
      case 'services':
	   echo("Services");
       break;  
      case 'gallery':
	   echo("Gallery");
       break;      
      case 'photos':
	   echo("Photos");
       break;  
      case 'events':
	   echo("Events");
       break;  
      case 'contact':
	   echo("Contact");
       break;
    }
  }
 ?>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: Back into PHP.

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Back into PHP.

Posted 27 September 2012 - 04:24 AM

But of course, your PHP code to change the variable is after your use of the variable.
Was This Post Helpful? 1
  • +
  • -

#3 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Back into PHP.

Posted 27 September 2012 - 04:29 AM

I put the head wrapper below the body wrapper, now it works. :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1