Jump to content


Photo

Includes help please...


  • Please log in to reply
7 replies to this topic

#1 hey_im_chris

hey_im_chris
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 July 2006 - 11:37 PM

Hey everyone,

Just a quick question I'd like to resolve tonight...

I have an index page that holds the php include script, and pages are called into that. The first page it calls has several links on it, which need to go to other pages in other directories, BUT, here's where the problem is: I don't know how to link to a page in another directory, since simply trying index.php?x=dir1/page tries loading index.php?x=page and that's it. Is there a way to write a filepath that fixes this problem?

If it helps, a basic look at my directory is:

Main Directory
  - dir1
      - page.php
  - index.php

I hope I've explained my problem sufficiently enough that somebody can explain to me what I need to do! Thanks in advance! :)

Chris

#2 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 12:49 AM

I'm not sure if this will help, but have you tried urlencode()

#3 hey_im_chris

hey_im_chris
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 July 2006 - 10:21 AM

I've never tried that before. How does it work? :)

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 July 2006 - 11:29 AM

Urlencode will not help. But what you might want to do is to create an array of all the pages that are in  different directories. The use an if statement to check the page being included if its in the array of pages in different directories. If it is use the path in the array for that page.

Sounds complicated? Its not but very straight forward if you understand arrays. Heres a quick demo of what I mean:
<?php

// check that 'page' is set in the url
if(isset($_GET['page']))
{
    // now we setup our array of pages in different folders
    // the following is the format of our array:
    // array([pagename] => array([filename], [path to file]));
    // Our pages array
    $pages = array("about" => array("index.php", "./about/"),
                   "contact" => array("contact.php", "./pages/"),
                   "products" => array("list-products.php", "./shop/")
                   );

    // Now we check wether the page needed to be included is in our pages array
    if(array_key_exists($_GET['page'], $pages))
    {
        // now we include our page:
        echo "include '" . $pages[$_GET['page']][1] . $pages[$_GET['page']][0] . "';";
    }
    // if it wasn't we presum its its in the same folder as this script
    else
    {
        echo "include './" . $_GET['page'] . ".php';";
    }

    echo "<br />\n<br />\n";
}

?>
Include: <a href="?page=about">About page</a> | <a href="?page=contact">Contact page</a> |
<a href="?page=products">Products</a> | <a href="?page=home">Home</a>


#5 hey_im_chris

hey_im_chris
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 July 2006 - 09:02 PM

Thanks for that! It seems quite straight-forward, actually. I'm a total php noob because I only learn what I need to when I need to use it. Tonight I'm learning about arrays! ;D

EDIT:
Okay, first of all, I'm having a bit of bother about how to load a page called 'gallery.php' as the default page that gets loaded at the start. Basically, what I want to achieve is:

1. index.php loads a text page with links to other pages called 'gallery.php'.
2. gallery.php has many links to pages in many other directories, which will load into index.php.

I could easily achieve this (as I have done already) with a simple iframe, but I don't want the inherent scrollbar and how I got past that in the past was to use a script that set the iframe dimensions to the exact dimension of the various pages it will load. BUT, that only worked in IE. This time, it is very important to me that the site works in Mozilla Firefox and Opera.

Thanks for your help so far, but if anyone can offer any advice about how to go about achieving my plan, I would be very damn grateful! :D

#6 hey_im_chris

hey_im_chris
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 06 July 2006 - 11:33 AM

*...16 hour bump* ::)

#7 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 06 July 2006 - 12:20 PM

so you want the links to open in the same page without reloading the entire page, or does that matter?
http://www.DaveLinger.com
dave at linger dot com

#8 hey_im_chris

hey_im_chris
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 06 July 2006 - 01:34 PM

I'd prefer to have it so that plain text pages will load into the main page (index.php), which holds the quite image-intensive layout design. Is that what you mean? :-\;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users