PHP Help.....
Results 1 to 4 of 4

Thread: PHP Help.....

  1. #1
    Banned
    Join Date
    Oct 2001
    Posts
    1,462

    PHP Help.....

    Ok, I had help and wrote a PHP program to print a different page banner on a page based on a variable input from the URL (For example index.php?task=about will print out About Us on the page) My code for the program is

    PHP Code:
    <?
        $hostname 
    "localhost";
        
    $db_user "root";
        
    $db_pass "mypass";
        
    $database "twn";
        
    mysql_pconnect($hostname,$db_user,$db_pass);
            
        If(
    $task == ""){$title "Welcome";};
        If(
    $task == "products"){$title "Products";};
        If(
    $task == "services"){$title "Services";};
        If(
    $task == "showcase"){$title "Showcase";};
        If(
    $task == "screenshots"){$title "Screenshots";};
        If(
    $task == "contact"){$title "Contact Us";};
        If(
    $task == "about"){$title "About Us";};
    ?>
    The code to print the title on the page is:

    PHP Code:
    <?=$title;?>
    To put the code into the page I use an include:
    PHP Code:
    <? include("inc/common.inc.php"); ?>
    Thank you for all your help =)

    PS: Is some sort of database entry requiered for this to work?

  2. #2
    Banned
    Join Date
    Nov 2001
    Posts
    43
    The bit of code you should will only change the title depending on what task is called. By the way...to get the different title to actually display you should use this bit of code:
    PHP Code:
    echo "<title>$title</title>"
    within the head tags.
    Another thing is...it would be much easier to use a switch statement instead of an if statement in this case. Use this code:
    switch($task) {
    case "products": $title = "Products"; break;
    case "services": $title = "Services"; break;
    case "showcase": $title = "Showcase"; break;
    case "screenshots": $title = "Screenshots"; break;
    case "contact": $title = "Contact Us"; break;
    case "about": $title = "About Us"; break;
    default:
    $title = "Welcome";
    }

    This script isnt very helpful as it doesnt even print out a page. However you can easily extend it. The easy way to do this task would be to add the line
    PHP Code:
    <?php include($page); ?>
    right after your body tag on the page. Then you would just create all the other pages as their own documents...like about.php, which would have the about page contents. Then, to make the correct page show up you just go to, for example, index.php?page=about.php.

  3. #3
    Banned
    Join Date
    Oct 2001
    Posts
    1,462
    The script does print out pages... There is more code which I did not think was relevant to this... Whe script prints out the content of a .inc file when a title is called

  4. #4
    Banned
    Join Date
    Nov 2001
    Posts
    43
    well what problem are you having with the code? You didnt even say.

Posting Permissions

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