简体   繁体   中英

Linking to other div from div in same page

I've found this script somewhere on this forum and it works fine. Unless you want to make use of folders in the backend. Then it's not working fine any more. So now my root folder is building files... Can someone look at this script and help me out? I'm not so used to PHP and MySQL but learning... ;-)

<div id="content">
    <?php 
    // All the page files, the first being the default value

    $pages=array('page1','page2','page3','page4','page5','page6', 'page7', 'page8');

    // Read $page variable from query string '?p='

    $page=isset($_GET['p'])?$_GET['p']:$pages[0];

    // Check if value of $page is allowed, assign default if not

    if(!in_array($page,$pages))
    {
        $page=$pages[0];
    }
    include($page . '.php'); 
    ?>
</div>

Within the header the links are formed like;

<a href="index.php?p=page1"></a>

This all works fine! But if you change this last code in;

<a href="start.php?p=chapters/page1"></a>

It won't work any more...

Please help...!

Just add chapters/ to the include path:

include('chapters/' . $page . '.php'); 

And keeping your HTML same:

<a href="index.php?p=page1"></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM