PDA

View Full Version : New to PHP and need help



Benedizione
04-15-2007, 10:41 PM
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

thetestingsite
04-15-2007, 10:46 PM
You could create a file called menu.txt and in there place the code you want your menu to have.

Example:


<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:


<?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):


<body>

<?php include('menu.txt'); ?>

</body>


Then this will be outputted to the browser:



<body>

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

</body>


Hope this helps.

boxxertrumps
04-15-2007, 11:14 PM
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

mburt
04-16-2007, 12:21 AM
you just make sure to escape the quotes...
Or use single-quotes.