|
|
Subject:
PHP, <?php include ("file.php"); ?> , file in cel
Category: Computers > Programming Asked by: johnjri1-ga List Price: $4.00 |
Posted:
04 Aug 2005 23:37 PDT
Expires: 03 Sep 2005 23:37 PDT Question ID: 551958 |
I know a little HTML and very little about PHP. I have two types of files: I have one file, let's call it menu.php (I'm not sure whether to save it as a .html file or a .php file). It has say 30 groups of links in it which are in groups something like this: <html> <head> <title></title> </head> <body> <!-- group #1--> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <!-- group #2--> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> etc. etc. <!-- group #30--> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> <a href="http://www.somplace.com">wordsbasically describing a page or site</a><br> </body> </html I have say 50 pages (again, I'm not sure whether to save it as a .html file or a .php file) that have a cel on the left that will contain the above menu. I want to use php to do this (not frames), something like this I was told: <td> <?php include("menu.php"); ?> </td> Like I said, lets say I have 50 pages. All are going to include this menu, but here is my question: On say the 20th, 37th, 45th pages I want to include only the portion of the "menu" in group 25. In ten other pages I want to include only the portion of the menu in group 3. etc etc. It will always be just one group. How do I do this? I'm guessing there are some tags I need to add to the menu file, and one unique line of code for each individual page. |
|
Subject:
Re: PHP, <?php include ("file.php"); ?> , file in cel
Answered By: hammer-ga on 05 Aug 2005 06:20 PDT Rated: |
johnjri1-ga, You can do this using a variable. Say you have three pages, each of which needs to show a different menu group. Before you do the include, set a variable indicating which menu group should appear on this page. In the samples below, the only thing that changes is the value of the $menu_group variable. page1.html looks like this. Note the $menu_group variable. <HEAD> </HEAD> <BODY> <?php $menu_group = 1; include("menu.php"); ?> </BODY> </HTML> page2.html looks like this: <HEAD> </HEAD> <BODY> <?php $menu_group = 2; include("menu.php"); ?> </BODY> </HTML> page3.html looks like this: <HEAD> </HEAD> <BODY> <?php $menu_group = 3; include("menu.php"); ?> </BODY> </HTML> Now that each page knows which menu it wants, menu.php needs to use that value to decide what to include. By using print statements, you can print only the appropriate menu group into the page. Note that the emebedded quote marks are preceded by a backslash. This is necessary to prevent parsing errors in the code. This tells PHP that you want a literal quote mark, rather than that the print string is ending. menu.php: <?php if($menu_group == 1) { print("<a href=\"http://www.somplace.com\">Menu 1 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 1 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 1 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 1 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 1 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 1 wordsbasically describing a page or site</a><br>\n"); } else if($menu_group == 2) { print("<a href=\"http://www.somplace.com\">Menu 2 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 2 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 2 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 2 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 2 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 2 wordsbasically describing a page or site</a><br>\n"); } else if($menu_group == 3) { print("<a href=\"http://www.somplace.com\">Menu 3 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 3 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 3 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 3 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 3 wordsbasically describing a page or site</a><br>\n"); print("<a href=\"http://www.somplace.com\">Menu 3 wordsbasically describing a page or site</a><br>\n"); } ?> To see this work, try the following links: http://www.hammerdata.com/Google/GA551958/page1.html http://www.hammerdata.com/Google/GA551958/page2.html http://www.hammerdata.com/Google/GA551958/page3.html Good luck with your web project! - Hammer Search strategy ---------------- None. Personal experience. Additional resources ---------------------- PHP Online Manual http://us3.php.net/manual/en/ | |
| |
| |
|
johnjri1-ga
rated this answer:
Thanks, It works :) |
|
Subject:
Re: PHP, <?php include ("file.php"); ?> , file in cel
From: dooga-ga on 30 Nov 2005 20:05 PST |
Awsome! A great answerer who made an example on a privately hosted site. Excellent service. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |