Click to See Complete Forum and Search --> : php to list menu text


OzzMosiz
06-11-2007, 01:00 PM
This is probably really simple (though not to me).

I have a webpage that I want to have text menus(with hyperlinks to other pages). Thing is I want all my web pages to have the same text menus, but don't want to update every single one, when something changes. I understand php is the best way to achieve this.

Can anyone point me to any examples on how to do this.

For the record I've never done any PHP whatsoever (though done some unix CGI scripting).

Thanks

scragar
06-11-2007, 09:13 PM
simply write you menu in a HTML file, call it something easy to renember like "menu.inc" (the extention can be anything realy, I prefare to always use inc for include on files that arn't realy supposed to be read directly, but serveral people would use HTM or HTML and some would insist on PHP, it realy doesn't matter).

then in all your pages to have the menu find the right place and write in:<? require "menu.inc"; ?> if you can't get this to work just let me know.

OzzMosiz
06-12-2007, 05:39 AM
simply write you menu in a HTML file, call it something easy to renember like "menu.inc" (the extention can be anything realy, I prefare to always use inc for include on files that arn't realy supposed to be read directly, but serveral people would use HTM or HTML and some would insist on PHP, it realy doesn't matter).

then in all your pages to have the menu find the right place and write in:<? require "menu.inc"; ?> if you can't get this to work just let me know.

I've tried this and it doesn't work. (i'm probably doing something wrong).
Could you give a really easy example?

scragar
06-12-2007, 06:01 AM
menu.inc<ul id='menu'>
<li><a href='index.php'>home</a></li>
<li><a href='somewhere.php'>there</a></li>
<li><a href='?'>here</a></li>
<li><a href='#'>top</a></li>
<li><a href='yawn.php'>yawn</a></li>
</ul>index.phpmy header content and such goes here, including some css:
<style type='text/css'>
#menu{
list-style: none;
float: left;
text-align: center;
}
</style>
</head><body>
<? require "menu.inc"; ?>
and you just geton with the pagecontent here.preview the effects here[/php], oh, andmake sure your files with the PHP code in havePHP perms either using the [url=http://www.desilva.biz/php/phpinhtml.html]htaccess (http://scragar.mybesthost.com/page.php) or by renaming them to end in .php

OzzMosiz
06-12-2007, 04:42 PM
scragar,

Works a treat. Thats the sort of thing I'm looking for.
What about if I want say a section from the .inc file in one place on my main page and another section on another part of the page.
Can you split the .inc into functions and the call on those function names within the main.php?

scragar
06-12-2007, 05:01 PM
just treat the included file just as you would any other file eg:
include.inc<?
function meap(){
echo "function called<br>";
};
?>caller.php<?
if(!@meap()){
echo "function failed<br>";
};
include "include.inc";
if(!@meap()){
echo "function failed<br>";
};
?>hope this helps you out.