944,216 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 12595
  • PHP RSS
Aug 21st, 2006
0

Calling a PHP function from HTML menu

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kibanga is offline Offline
6 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Please Help! parse error, unexpected T_STRING
Next Thread in PHP Forum Timeline: How to rotate top page banner using php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC