Results 1 to 4 of 4

Thread: New to PHP and need help

  1. #1
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default New to PHP and need help

    A month or so ago this php stuff was briefly explained to me but I am just now getting around to experimenting with it on my site. I understand that with php I can create a menu from a "menu.txt" page, add a php code >><?php menu(TRUE); ?><<to all of my pages (change all my pages from "htm" to "php") and that menu from "menu.txt" will show up on all of my pages. Correct?

    I am not sure what was meant by this....does the following code go on every page of the website too?

    Quote:
    make sure you have the php file with the function included in your pages with the menu:
    <?php include "path/to/file.php"; ?>
    Unquote

    How do I create the kind of menu that I want? How do I change physical appearances and such?

    I think I am supposed to use a code like this on my "menu.txt" page:

    echo "<div class=\"item\"><a href=\"". $one['0'] ."\">". $one['1'] ."</a></div>\r\n<div class=\"spacer\"></div>";

    But where does the url go? I am confused by the back slashes in the code instead of forward slashes.

    Andrea

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could create a file called menu.txt and in there place the code you want your menu to have.

    Example:
    Code:
    <div id="menu">
    <a href="test.php">This is a test link</a>
    </div>

    Then on all the pages you want the menu to appear, place this code:
    Code:
    <?php
    include('menu.txt');
    ?>
    That will include the contents (in this case, the source code for your menu) in the php document you place the above code in. So, if you have a file like this:

    example.php (from the body tag):
    Code:
    <body>
    
    <?php include('menu.txt'); ?>
    
    </body>
    Then this will be outputted to the browser:

    Code:
    <body>
    
    <div id="menu">
    <a href="test.php">This is a test link</a>
    </div>
    
    </body>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I remember this...
    if you want to have your own markup for the menu...
    echo "<div class=\"item\"><a href=\"". $one['0'] ."\">". $one['1'] ."</a></div>\r\n<div class=\"spacer\"></div>";
    makes each item into
    <div class="item"><a href="URL">TEXT</a></div>\r\n<div class="spacer"></div>

    If you wanted:
    <a href="url">text</a><br />\r\n
    you would have
    echo "<a href=\"". $one['0'] ."\">". $one['1'] ."</a><br />\r\n";
    you just make sure to escape the quotes...

    EDIT: customiseable version here; http://boxxertrumps.bo.funpic.org/?source
    Last edited by boxxertrumps; 04-21-2007 at 02:26 PM.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    you just make sure to escape the quotes...
    Or use single-quotes.
    - Mike

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
  •