PHP, <?php include ("file.php"); ?> , file in cel
I need to limit the results in <?php include ("file.php"); ?> ..........
I just got a google answer which I am very satisfied with regarding a
php file. I had a second thought after I asked it. Let me first show
the link and copy/paste the answer to set up the new question:
---------------------------------------------------------------------------------------------------------------
http://answers.google.com/answers/threadview?id=551958#a
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
--------------------------------------------------------------------------------------------------------------
Some of the menu groups will have as much as 30 + items. I want to be
able to insert a variable in the code to limit the number of results
that I can change when needed. For example, if a menu group has 30
items I want to be able to choose say 10 (or whatever) items to
include starting from the top. (items 11-30 will not be included).
How do I do this? |
Clarification of Question by
johnjri1-ga
on
05 Aug 2005 15:57 PDT
I'm a little disapointed the question was locked for so long and no
answer. If it makes it easier I have the ability to rapidly insert a
unique number/ code in front of each menu item, that is not a problem.
So maybe instead of $menu_group = 3; type of answer,,, it could
somehow tell it to print group 3, items 1-10. Each group would have
to sart over at one (1) however. Maybe this makes it easier. I hope
this makes sense.
|