tones31
tones31

Reputation: 167

Using PHP include to include a file with it's own included file

I am trying to load a projects.php file into a higher-level index.php file and want to maintain all the .js .css and any further nested (in .js files) .php files, that are declared in the projects.php file.

My index.php file goes like:

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BLST</title>
</head>

<body>
    <?php $projectsPage = "/tables/php/projects.php"?>
    <li><a href="index.php?page=<?php echo $projectsPage;?>">Projects</a></li>
    <?php if(is_null($_GET["page"])) { 
                $page = ""; 
        }else{ 
            $page = $_GET["page"]; 
        } 
       include($page); 
    ?>
</body>
</html>

My projects.php file is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />

        <title>Projects</title>

        <style type="text/css">
            @import "css/test.css";
            @import "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/themes/smoothness/jquery-ui.css";
        </style>

        <script type="text/javascript" language="javascript" charset="utf-8" src="js/jquery.min.js"></script>
    </head>

The issue is that none of the files in projects.php are found. This is because the browser is looking to my main directory now (where index.php is).

Upvotes: 0

Views: 95

Answers (1)

Vagabond
Vagabond

Reputation: 897

The test.css is in "tables/php/css/test.css" and what about the location of projects.php and index.php.

I think the answer to these will solve the problem.

Upvotes: 1

Related Questions