Results 1 to 9 of 9

Thread: Simple(I hope) PHP script problem.

  1. #1
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Question Simple(I hope) PHP script problem.

    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 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!
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  2. #2
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Hi, fileserverdirect!

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

    PHP Code:
    if ($general "yes"
    add to this instead:
    PHP Code:
    if ($general == "yes"
    OBS!! - REMOVE ALL ; AFTER }; AND ADD THEM AFTER
    PHP Code:
    $general "yes" Add here-> ; 
    Here are the code:
    PHP 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
    Last edited by mbrodin; 05-29-2007 at 08:24 PM.

  3. #3
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Hi again!

    You can also do this way:

    PHP Code:
    <?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

  4. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    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:
    PHP Code:
    if ($general == "yes") {
    document.title "$begintitle $pagetitle &bull; $gentitle";

    Is there any other way to target the title?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  5. #5
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Quote Originally Posted by fileserverdirect View Post
    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:
    PHP Code:
    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
    PHP Code:
    if ($general == "yes") { 
    document.title "$begintitle $pagetitle &bull; $gentitle"

    change to this:
    PHP Code:
    if ($general == "yes") { 
    $title "$begintitle $pagetitle &bull; $gentitle"



    Best regards,
    mbrodin

  6. #6
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    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
    Last edited by fileserverdirect; 05-29-2007 at 09:34 PM. Reason: Needed to add what post I was based of of.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  7. #7
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Quote Originally Posted by fileserverdirect View Post
    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

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Smile

    Thanks Guys! Evreything works, and I am happy, it's a good state of mind
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •