LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2009, 10:04 PM   #1
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Rep: Reputation: 30
Question Using php to call am html file


I have some files I am trying to get to communicate with my main file default.php. So what have is menu.css (takes care of my sidebar), menu.htm (contains JS for all the submnmenus and such), topmenu.htm (has JS for the top menu), and footer.htm (same as the other 2 but obviously footer) , default.css (takes care of all other css info). So what I am trying to do is call the .html files from default.php so that I don't have a .html file with all this excess JS everywhere. so here is what I have in default.php
Code:
//this is the very top lines//
<?php include("menu.htm"); ?>
<?php include("topmenu.htm"); ?>
<?php include("footer.htm");?>

//html stuff that was prexisting

<?php topmenu(); ?>
//this is placed where I want the menu followed by content//


<?php menu(); ?>  //located where that menu goes



<?php footer();?> //located at the bottom where the footer goes
I have used this technique calling a .php script to a .php file. but I am not sure if it works the same way.

hopefully this is clear enough.
 
Old 10-13-2009, 10:45 PM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Just try it.

If it does not work, you can do the following
rename topmenu.htm to topmenu.php; if your server parses htm files as php, this step is not necessary but I consider it neater.
edit topmenu.php
Code:
<?php
function topmenu() {
?>
your original html content here
<?php
}
?>
The first three lines open a function called topmenu and the last three lines close the function. The content in between is treated as html.

You can now include topmenu.php in your other php files and call topmenu(). Repeat this step for the other files.
 
Old 10-13-2009, 10:50 PM   #3
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Original Poster
Rep: Reputation: 30
did try it...doesn't display anything.
 
Old 10-13-2009, 11:02 PM   #4
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Original Poster
Rep: Reputation: 30
Still nothing, do I need to remove the <html> tags at the beginning and the end of the menu.php, topmenu.php, footer.php? Also do I still include them like did above in default.html?
and lastly should I do anything special with the JS inside what I just made into a .php script? or are the included html tags surrounding them work just fine?
 
Old 10-14-2009, 04:32 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Sorry, the existing html should only be the stuff that's inside the body tags (so excluding the body tags.

Code:
<?php
include("menu.php");
include("topmenu.php");
include("footer.php");
?>
<html>
<header>
</header>
<body>

<?php
topmenu();
menu();
footer();
?>
</body>
</html>

Below is how I use it
page.inc.php
Code:
<?php

include("../inc/menu.inc.php");

function do_htmlheader($title="")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<?php
    echo "<head>\n";
    if(isset($_SESSION['db']))
    {
        $db=strtoupper($_SESSION['db']);
        echo "<title>Incident Logging System - $db - $title</title>\n";
    }
    else
        echo "<title>Incident Logging System - $title</title>\n";
    echo "<link rel=\"stylesheet\" href=\"btd2.css\" type=\"text/css\">\n";
    echo "<link rel=\"stylesheet\" href=\"menu.css\" type=\"text/css\">\n";
?>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<script type="text/javascript">
<!--
window.onload=montre;

/******************/
/* show a submenu */
/******************/
function montre(id)
{
    var d = document.getElementById(id);
    // hide submenus
    for (var i = 1; i<=10; i++) {
        if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
    }
    if (d) {
        d.style.display='block';
    }
    else
    {
    }
}

//-->
</script>

<?php
    echo "</head>\n";
    // we add a montre (show) here to remove open menus when a user clicks on another element
    echo "<body>\n";

    echo "<div id=\"menu\">\n";
    display_menu();
    echo "</div>\n";

    // if one puts the onclick event in the body, the context menu for the submenus does not work with the mouse
    // it confused me as a user and will definitely confuse other users
    echo "<div id=\"site\" onclick=\"javascript:montre();\">\n";

    if(isset($_SESSION['db']))
    {
        $db=strtoupper($_SESSION['db']);
        echo "<h1>Incident Logging System ($db)<hr />$title</h1>\n";
    }
    else
    {
        echo "<h1>Incident Logging System<hr />$title</h1>\n";
    }
}

function do_htmlfooter()
{
    echo "</div>\n";
    echo "</body>\n";
    echo "</html>\n";
}
?>
The function display_menu() is defined in menu.inc.php
Code:
<?php
function display_menu()
{
// menu taken from
//   http://tutorials.alsacreations.com/modelesmenus/hd1.htm
//   http://tutorials.alsacreations.com/modelesmenus/hd2.htm
// slightly modified (css and added onfocus) and converted to php

?>
I don't escape from php as the menu content dependfs on the login of the user
<?php
}
?>
I include page.inc.php in every page that I have
Code:
<?php
include ("../inc/page.inc.php");

do_htmlheader("Incident Overview");

// other PHP code specific for the page

do_htmlfooter();
?>
Hope this helps enough. And check your server logs to see where it goes wrong.
 
Old 10-16-2009, 11:11 AM   #6
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Original Poster
Rep: Reputation: 30
Thank you I will try that. I am unable to edit right now so I will let you know in the next day or so if it works
 
Old 10-21-2009, 12:42 PM   #7
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Original Poster
Rep: Reputation: 30
ok so I have everything KINDA working, the site finds all the image stuff I need. Now my question is how to get the Java Script working for the menu's submenus. I have tried including the exported .htm and what I just converted to .php The only issue is in the side menu not showing the submenu on mouseover like it does if I just run that HTML. I have the pages included correctly cause all of the images are called with the .htm and .php pages that I mentioned above. it is just not using the javascript.
 
Old 10-21-2009, 04:44 PM   #8
jus71n742
Member
 
Registered: Apr 2008
Distribution: Ubuntu 8.04 64bit/ 32bit, FreeBSD 8
Posts: 185

Original Poster
Rep: Reputation: 30
never mind, i forgot a file.
 
Old 10-21-2009, 11:27 PM   #9
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Great. Please mark your thread as solved using the thread tools just above the first post on the page.
 
  


Reply

Tags
html, javascript, php


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
when call shell script file from php mohan.aturheart Programming 1 07-02-2008 01:33 AM
error from .php file call in cron just_me_then Linux - Newbie 1 01-07-2007 02:52 AM
call a php file petenyce Linux - Newbie 3 11-23-2005 03:21 AM
php in an .html file does not work NW Otter Linux - Software 4 09-23-2003 04:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration