This is a discussion on "include problem" within the PHP Forum section. This forum, and the thread "include problem are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
include problem
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
||||
|
||||
|
Right,
I have a php script that shows how many users there are in the database:
i tried putting "12" before "<?php" and "34" after "?>" but it came up as "12 34". What's wrong? You can have more than 1 include on a page right? Because it's also including 'navigation.php' thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|
|
#2
|
||||
|
||||
|
Re: include problem
oh forgot to say the script works,
as in just navigating to /content/totalusers.php will show "Currently we have x users"
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#3
|
|||
|
|||
|
Re: include problem
You can include more than one page, that's not the problem. Make sure the url is right (try replacing 'include' with 'require' and see if you get errors).
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
#4
|
|||
|
|||
|
Re: include problem
You can use relative paths in include.
So your include should be something like this
|
|
#5
|
||||
|
||||
|
Re: include problem
umm it still didn't work :/
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#6
|
|||
|
|||
|
Re: include problem
hey try
<!--#include file ="folderdestination/incfilename.inc" --> |
|
#7
|
|||
|
|||
|
Re: include problem
are you sure you have the path to the include right?
Where is the include found? www.yourdomain.com/content/totalusers.php ? or something like www.yourdomain.com/php/content/totalusers.php ? Maybe you should take the first slash off of the include path. Like this... <?php include('content/totalusers.php'); ?> Last edited by JacobHaug; Nov 13th, 2007 at 13:58. Reason: Taking out main domain |
|
#8
|
||||
|
||||
|
Re: include problem
taking the slash of worked
thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#9
|
|||
|
|||
|
Re: include problem
lol. No problem.
using the slash makes the url: http://www.yourdomain.com/content/ but without it makes it: http://www.yourdomain.com/yourfolder/content/ Just so you know. Last edited by JacobHaug; Nov 13th, 2007 at 13:59. Reason: Removed at users request! |
|
#10
|
|||
|
|||
|
Re: include problem
Quote:
True for the browser, but remember that PHP is server side, and when you include files with include/require (or better practice, include_once/require_once), then you are (usually) specifying and including a file path and not a URI. So include('/content/totalusers.php') was trying to include totalusers.php from the directory /content (i.e. directory content in the root directory) rather than from the directory 'content' in the same directory as the main script. PHP will emit a warning when it cannot include a file, but if displaying errors has been disabled then no error would be seen, and in this case logging would probably be to a file. It's a good idea to find out where errors are going as diagnosing problems is tricky without that! Coding the correct include path can sometimes be tricky in PHP as the current directory is not always where you expect it to be or the same in all cases. This is particularly the case if file A.php includes subdir/B.php, and A.php is included from files in different directories. One technique is to construct an absolute path based on where a script is running. The pseudo constant __FILE__ holds the currently executing files full path, and using the function dirname(), you can extract the directory in order to locate files relative to that. e.g. in A.php: include_once dirname(__FILE__) . '/subdir/B.php'; This ensures that no matter where A.php is located and independent of the current directory, if subdir/B.php is always in the same directory as A.php then A.php can include B.php no matter where the files are located, what the current directory is and where A.php has been included from. hth Last edited by JacobHaug; Nov 13th, 2007 at 14:00. |
|
#11
|
|||
|
|||
|
Re: include problem
*stands and gapes in awe of this wonderfully elegant solution to one of his biggest problems*
Now that was interesting. Thanks ioncube
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
#12
|
||||
|
||||
|
Re: include problem
Wow big post
and handy
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
![]() |
| Tags |
| include |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can I use #include within an If Then statement? | Donny Bahama | Classic ASP | 5 | Jul 30th, 2006 18:29 |
| js include | timmytots | JavaScript Forum | 5 | Jul 8th, 2006 12:43 |
| JS include | timmytots | JavaScript Forum | 5 | Jun 16th, 2006 01:49 |
| Help need with php include!! | allstar | PHP Forum | 7 | Dec 29th, 2005 15:09 |
| Include Virtual on IIS | jakenoble | PHP Forum | 3 | Mar 8th, 2004 07:22 |