| | |
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 |
advanced alerts apache api archive array autosuggest beginner binary broken cakephp checkbox class clients cms code cron curl database date datepart display dynamic echo email emptydisplayvalue eregi error execute explodefunction file files folder form forms function functions google hack head href htaccess html if...loop image include insert ip javasciptvalidation javascript joomla keywords library limit link login mail matching menu mlm multiple mysql number object oop password paypal pdf php phpincludeissue query radio random recursive remote script search searchbox server sessions shot smarty source space speed sql syntax system table tutorial update upload url validator variable vbulletin video web website youtube





