| | |
Calling a PHP function from HTML menu
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2006
Posts: 6
Reputation:
Solved Threads: 0
I have files of several with geographical information of several places and animals that i want to be accesed by through the menu. Here is an outline of my project; I have simplified it by taking only parts that are relavent for my questions below.
I have a PHP class defined as follows:
[php]
<?php//=================================================
//mymain.php
class mysite
{ var $pagetitle;
var $pagefile;
function setsite($title,$contents)
{
$this->pagetitle=$title;
$this->pagefile=$contents;
}
function menu()
{
include_once("mymenu.php");
}
function content()
{
$pagetitle=$this->pagetitle;
$contentsfile=$this->pagefile;
include_once("mycontents.php");
}
}
//=================================================
?>[/php]
The function menu calls a "mymenu.php" file to set up the menus. A typical setup of myenu.php is as follows:
[php]<?php
//=================================================
// mymenu.php.
?>
<div class="menu">
<ul>
<li class="Animals"><a href="..">Animals
<table><tr><td>
<ul>
<li class="Elephants"><a href="..">Elephants</a></li>
<li class="Lions"><a href="..">Lions</a></li>
<li class="Zebras"><a href="..">Zebras</a></li>
</ul>
</td></tr></table></a>
</li>
<li class="Places"><a href="..">Places
<table><tr><td>
<ul>
<li class="Brazil"><a href="..">Brazil</a></li>
<li class="South Africa"><a href="..">South Africa</a></li>
<li class="Malaysia"><a href="..">Malaysia</a></li>
</ul>
</td></tr></table></a>
</li>
</ul>
</div>
?>[/php]
As it can be seen, this menufile is not complete; that is where my questions are. Before I pose my questions, let me finish up a few more codes.
Since function "content' in this class requires, "mycontents.php", is created it as follows:
[php]<?php
//=================================================
// mycontents.php.
?>
<h2><? echo $pagetitle;?></h2>
<hr>
</div>
<?
include_once($contentsfile);
//=================================================
?>[/php]
Basically, this file displays the $pagetitle, and opens a $contentsfile. Someone may question this organisation but my actual file larger file requires it to be so.
Finally, I have my font code file as follows:
[php]<?php
//=================================================
// mymain.php.
include_once("mysitecls.php");
$thissite = new mysite;
$thissite->setsite("My World Travels","mydefault_contents.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<html>
<head>
<title><?echo $thissite->pagetitle?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="all" type="text/css" href="far-mex.css" />
</head>
<body>
<div id="leftcol" >
<? $thissite->menu(); ?>
</div>
<div id="leftcol" >
<? $thissite->content();?>
</div>
</body>
</html>
<?
?>
[/php] Basically it initilizes the class with a file tile of "My World Travels" where the file contents are in "mydefault_contents.php". After that the user through the menu selects what a topic to be displayed, each selection has to set up a string with for $pagetitle (i.e the title of the topic) and a string for the $pagefile (i.e. file name with details of the topic). This construction is in complete in the menufile shown above, which is the center of my questions:
I have three questions:
(1) For wathever url adress I put in the <a href=".."> tags, the menu keeps opening the root directory when viewed in in Netscape 8.1 (based on firefox); although it works quite well with Internet Explorer V 7.0.5296.0 (beta). My first question is, what makes my menu code fail in netscape while it works in internet explorer.
(2) How can I make my menu to establish the values of $pagetitle and $pagefile using the internal "setsite" function of 'mysite' class without opening another file which can replace my current screen. In fact I want the screen layout to remain intact, only the left pane of the screen is to be updated.
(3) After the the values of $pagetitle and $pagefile are set in the class, will that automatically cause the screen contents (in the left pane) to be updated?
I am not sure where my questions are clear, but this time I tried to post as much information as possible.
Any help will be highly appreciated.
I have a PHP class defined as follows:
[php]
<?php//=================================================
//mymain.php
class mysite
{ var $pagetitle;
var $pagefile;
function setsite($title,$contents)
{
$this->pagetitle=$title;
$this->pagefile=$contents;
}
function menu()
{
include_once("mymenu.php");
}
function content()
{
$pagetitle=$this->pagetitle;
$contentsfile=$this->pagefile;
include_once("mycontents.php");
}
}
//=================================================
?>[/php]
The function menu calls a "mymenu.php" file to set up the menus. A typical setup of myenu.php is as follows:
[php]<?php
//=================================================
// mymenu.php.
?>
<div class="menu">
<ul>
<li class="Animals"><a href="..">Animals
<table><tr><td>
<ul>
<li class="Elephants"><a href="..">Elephants</a></li>
<li class="Lions"><a href="..">Lions</a></li>
<li class="Zebras"><a href="..">Zebras</a></li>
</ul>
</td></tr></table></a>
</li>
<li class="Places"><a href="..">Places
<table><tr><td>
<ul>
<li class="Brazil"><a href="..">Brazil</a></li>
<li class="South Africa"><a href="..">South Africa</a></li>
<li class="Malaysia"><a href="..">Malaysia</a></li>
</ul>
</td></tr></table></a>
</li>
</ul>
</div>
?>[/php]
As it can be seen, this menufile is not complete; that is where my questions are. Before I pose my questions, let me finish up a few more codes.
Since function "content' in this class requires, "mycontents.php", is created it as follows:
[php]<?php
//=================================================
// mycontents.php.
?>
<h2><? echo $pagetitle;?></h2>
<hr>
</div>
<?
include_once($contentsfile);
//=================================================
?>[/php]
Basically, this file displays the $pagetitle, and opens a $contentsfile. Someone may question this organisation but my actual file larger file requires it to be so.
Finally, I have my font code file as follows:
[php]<?php
//=================================================
// mymain.php.
include_once("mysitecls.php");
$thissite = new mysite;
$thissite->setsite("My World Travels","mydefault_contents.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<html>
<head>
<title><?echo $thissite->pagetitle?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="all" type="text/css" href="far-mex.css" />
</head>
<body>
<div id="leftcol" >
<? $thissite->menu(); ?>
</div>
<div id="leftcol" >
<? $thissite->content();?>
</div>
</body>
</html>
<?
?>
[/php] Basically it initilizes the class with a file tile of "My World Travels" where the file contents are in "mydefault_contents.php". After that the user through the menu selects what a topic to be displayed, each selection has to set up a string with for $pagetitle (i.e the title of the topic) and a string for the $pagefile (i.e. file name with details of the topic). This construction is in complete in the menufile shown above, which is the center of my questions:
I have three questions:
(1) For wathever url adress I put in the <a href=".."> tags, the menu keeps opening the root directory when viewed in in Netscape 8.1 (based on firefox); although it works quite well with Internet Explorer V 7.0.5296.0 (beta). My first question is, what makes my menu code fail in netscape while it works in internet explorer.
(2) How can I make my menu to establish the values of $pagetitle and $pagefile using the internal "setsite" function of 'mysite' class without opening another file which can replace my current screen. In fact I want the screen layout to remain intact, only the left pane of the screen is to be updated.
(3) After the the values of $pagetitle and $pagefile are set in the class, will that automatically cause the screen contents (in the left pane) to be updated?
I am not sure where my questions are clear, but this time I tried to post as much information as possible.
Any help will be highly appreciated.
![]() |
Similar Threads
- How to call a PHP function from Javascript and return the results back into Javascrip (PHP)
- Returning HTML code through SQL query? (PHP)
- Calling function to add HTML to the page (ASP.NET)
- PHP code not blending with HTML (PHP)
Other Threads in the PHP Forum
- Previous Thread: Please Help! parse error, unexpected T_STRING
- Next Thread: How to rotate top page banner using php
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cache cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic email error file filter folder form forms forum function functions gc_maxlifetime google header headmethod howtowriteathesis href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation neutrality oop parameter parsing paypal pdf php phpmysql query question random recourse regex script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube





