Jump to content

ferdri3

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Posts posted by ferdri3

  1. for if anyone wants to know, here is the text version:

     

    <?php
    switch (basename($_SERVER['PHP_SELF'])) {
        case 'index.php':
            $txt = "Line of Text 1";
            break;
        case 'anotherpage.php':
            $txt = "Line of Text 2";
            break;
    }
    echo '<h2>', $txt ,'</h2>';
    ?>
    

     

    If you dont want the text to be a header,

     

    replace:

    echo '<h2>', $txt ,'</h2>';

    with:

    echo $txt;

  2. The PHP will be gone because it is processed before it hits your browser.

    Anyway, in your code you are assigning the image path to a variable but arent doing anything with it :)

    switch (basename($_SERVER['PHP_SELF'])) {
        case 'test1.php':
            $image = 'images/image1.png';
            break;
        case 'test2.php':
            $image = 'images/image2.png';
            break;
    }
    echo '<img src="', $image , '">';

     

    The echo made it work!

    HUGE thanks to all of you!

  3. Thanks for the fast replies!

     

    I've set up a test server:

    www.meesterferdi.net/test1.php

    www.meesterferdi.net/test2.php

     

    This is what I have now:

     

    test1.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <!--  START title & keywords & description  -->
    <title>Test Homepage</title>
    <meta content="keywords" name="keywords" />
    <meta content="testing page" name="description" />
    <!--  !END! title & keywords & description  -->
    <!--  START CSS stylesheetlinks  -->
    <link href="css/test.css" rel="stylesheet" type="text/css" />
    <!--  !END! CSS stylesheetlinks  -->
    </head>
    <body style="margin: 0">
    <?php include("menu.php"); ?>
    </body>
    </html>
    

     

    test2.php looks the same.

     

    menu.php

    <div id="menu">
    <ul>
    	<li>
    		<a href="menu1.php" title="menu1">menu1</a>
    	</li>
    	<li>
    		<a href="menu2.php" title="menu2">menu2</a>
    	</li>
    	<li>
    		<a href="menu3.php" title="menu3">menu3</a>
    	</li>
    	<li>
    		<a href="menu4.php" title="menu4">menu4</a>
    	</li>
    	<li>
    		<a href="test1.php" title="test1">test1</a>
    	</li>
    	<li>
    		<a href="test2.php" title="test2">test2</a>
    	</li>
    </ul>
    </div>
    <div id="title_img">
    <?php
    switch (basename($_SERVER['PHP_SELF'])) {
        case 'test1.php':
            $image = 'images/image1.png';
            break;
        case 'test2.php':
            $image = 'images/image2.png';
            break;
    }
    ?>
    </div>
    

     

    test.css

    /*  START menu style  */
    
    ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    img {
        border: none;
    } 
    #menu {
    position: relative;
    float: left;
        width: 200px;
        margin: 10px;
    }
    #menu li a {
        height: 32px;
        voice-family: "\"}\""; 
        voice-family: inherit;
        height: 24px;
        text-decoration: none;
    }    
    #menu li a:link, #menu li a:visited {
    font-family:Arial, Helvetica, sans-serif;
        color: #000;
        display: block;
        background:  url(../images/include/menu.gif);
        padding: 8px 0 0 30px;
    }
    #menu li a:hover {
        color: #2f5bb7;
        background:  url(../images/include/menu.gif) 0 -32px;
        padding: 8px 0 0 30px;
    }
    /*  !END! menu style  */
    
    #title_img {
    position: relative;
    width: 670px;
    height: 192px;
    float: left;
    }
    

     

    The menu displays just fine, but the images dont appear.

  4. Hello person who reads this now ;)

     

    I work a lot with <?php include("..."); ?> and I never thought beyond the html I put in there.

     

    In 1 of the include files I have the set-up of a simple vertical html/css menu and on the right next to it

    I have an image. However, not every page on my website needs the same image and I probably will change

    a lot of them frequently.

     

    Now I was wondering if (and how) I could include a piece of PHP code which does the following:

     

    If the web-url is "page1.php" show "image1.png"

    If the web-url is "page2.php" show "image2.png"

    If the web-url is "page3.php" show "image3.png"

    etc.

     

    This way I only have to change the "imageX.png" in 1 file.

     

    I hope you can help me.

     

    Best regards and thanks in advance!

    Ferdri3

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.