lkbolt Posted November 29, 2010 Share Posted November 29, 2010 I have written the following php statement and it works to show pages titles if I have an id in the url example. www.mysite.com/index.php?id=3 then the right page title is displayed but if I am on my home page www.mysite.com with no id the page title isn't displayed. I am running the code in the header in the title brackets. here is the code. The last else doesn't display my home page title any help would be great thank you very much... <title> <? if (isset($_GET['id'])) if($_GET['id'] == '1') { echo "LBT Services Page"; } else if($_GET['id'] == '2') { echo "About LBT"; } else if($_GET['id'] == '3') { echo "Contact LBT"; } else if($_GET['id'] == '4') { echo "Your Message to LBT has been Submitted"; } else if($_GET['id'] == '5') { echo "LBT Links Page"; } else if($_GET['id'] == '6') { echo "LBT Back-UP Plans"; } else { echo "LBT Home page"; } ?></title> Quote Link to comment Share on other sites More sharing options...
menator Posted November 29, 2010 Share Posted November 29, 2010 your first if is asking what to do if id is set. Not what to do if id is not set not. Quote Link to comment Share on other sites More sharing options...
lkbolt Posted November 29, 2010 Author Share Posted November 29, 2010 I trying to find out how to make it display my title if there is no id. thanks Quote Link to comment Share on other sites More sharing options...
menator Posted November 29, 2010 Share Posted November 29, 2010 <title> <? if (isset($_GET['id'])) { if($_GET['id'] == '1') { echo "LBT Services Page"; } else if($_GET['id'] == '2') { echo "About LBT"; } else if($_GET['id'] == '3') { echo "Contact LBT"; } else if($_GET['id'] == '4') { echo "Your Message to LBT has been Submitted"; } else if($_GET['id'] == '5') { echo "LBT Links Page"; } else if($_GET['id'] == '6') { echo "LBT Back-UP Plans"; } else { echo "LBT Home page"; } }//first if else { echo 'LBT Home Page'; } ?> </title> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 29, 2010 Share Posted November 29, 2010 How about a way with no "if" statements: <?php $title_array = array('LBT Home page','LBT Services Page','About LBT','Contact LBT','Your Message to LBT has been Submitted','LBT Links Page','LBT Back-UP Plans'); $id = (isset($_GET['id']))?$_GET['id']:0; $title = (array_key_exists($id,$title_array))?$title_array[$id]:$title_array[0]; echo "<title>$title</title>\n"; ?> Using this code makes it very easy to add anothere title without having to worry whether you've added the "if" block correctly. Ken Quote Link to comment Share on other sites More sharing options...
lkbolt Posted November 29, 2010 Author Share Posted November 29, 2010 Thanks for the replies I will try both solutions and let you know how it goes. Thanks very much for the help.... Quote Link to comment Share on other sites More sharing options...
lkbolt Posted November 29, 2010 Author Share Posted November 29, 2010 Thanks kenrbnsn and menator both solutions worked beautifully. This is why I love this site. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.