Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-08-2009, 11:47 AM Include all files
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
I want to include all the files in one directory in a switch statement. SO far I have this:

PHP Code:
<?php
switch($_SERVER['PHP_SELF'])
{
     case 
'/travel.php':
          echo 
'<div id="top">';
          break;
     case 
'/sports.php':
          echo 
'<div id="top1">';
          break;
     case 
'/politics.php':
          echo 
'<div id="top2">';
          break;
     case 
'/index.php':
          echo 
'<div id="top3">';
          break;
     case 
'/submit.php':
          echo 
'<div id="top3">';
          break;
     case 
'/links.php':
          echo 
'<div id="top3">';
          break;
     case 
'/column.php':
          echo 
'<div id="top3">';
          break;
     case 
'/funny.php':
          echo 
'<div id="top3">';
          break;
default:
  echo 
'<div>';
}
?>
I want another case statement so that instead of including just one page like I have right now, it would include all the files in a directory such as 'travel'.

I don't know if this is very clear or not?

Thanks
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-08-2009, 01:27 PM Re: Include all files
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Just to clarify, when you say you want to include files do you mean include them as in
PHP Code:
include('file.php'); 
If so your code would look something like this:
PHP Code:
$dir opendir('/');

while(
$file readdir($dir))
{
     
$ext strrchr($file'.')
     if(
$ext == '.php')
     {
          include_once(
$file);
     }
}

closedir($dir); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-08-2009, 02:07 PM Re: Include all files
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
Nope.

Instead of
PHP Code:
<?php
switch($_SERVER['PHP_SELF'])
{
     case 
'/travel.php':
          echo 
'<div id="top">';
          break;
?>
I want something like
PHP Code:
<?php
switch($_SERVER['PHP_SELF'])
{
     case 
'/travel/...':
          echo 
'<div id="top">';
          break;
}
Where ''/travel/...'' is a directory. How would I make '<div id="top">' appear in the source code of all files within the directory 'travel'.

For example I want a page like http://mypage.com/travel/mexico.php to have '<div id="top"> in it's source code
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Old 04-08-2009, 02:24 PM Re: Include all files
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
For something like this I think it would be better to use dynamic content (pulling content from a database). Instead of using static files (ie /travel/mexico.php) use a single file that fetches the data (travel.php?location="mexico"). Any changes in travel.php would then effect each location.

If however, you want to stick to static files, you'll need to include a common file in each static page.

PHP Code:
<?php
$dir 
str_replace('/'''__DIR__);
switch(
$dir)
{
     case 
'travel'
          
echo '<div id="top">';
          break;
}
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-08-2009, 02:31 PM Re: Include all files
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
Yeah. I want to use a database, and will prboably set one up in the future, but I don't know a lot about them, plus I'm using another company's host and I'm not sure how to connect to their mysql.

Since you brought that up. Could you show me some links on how to set up a flat file database,for my pages?

Thanks
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Old 04-08-2009, 02:38 PM Re: Include all files
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
If you have to use flat files look into XML
http://xtech06.usefulinc.com/schedule/paper/19
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-08-2009, 10:32 PM Re: Include all files
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
Ok. Sorry for not posting this earlier, but about your previous code. I modified it a little to suit my needs. It now looks like this...
<?php
$dir = str_replace('/', '', __DIR__);
switch($dir)
{
case 'travel':
echo '<div id="top">';
break;
case 'sports':
echo '<div id="top1">';
break;
case 'politics':
echo '<div id="top2">';
break;
case 'submit':
echo '<div id="top3">';
break;
case 'links':
echo '<div id="top3">';
break;
case 'column':
echo '<div id="top3">';
break;
case 'funny':
echo '<div id="top3">';
break;
default:
echo '<div>';
}
?>

It doesn't work though, and I'm not sure why. No errors showed up, it just doesn't display the <div> tags. I also have some code before it

<?php
switch($_SERVER['PHP_SELF'])
{
case '/travel.php':
echo '<div id="top">';
break;
case '/sports.php':
echo '<div id="top1">';
break;
case '/politics.php':
echo '<div id="top2">';
break;
case '/index.php':
echo '<div id="top3">';
break;
case '/submit.php':
echo '<div id="top3">';
break;
case '/links.php':
echo '<div id="top3">';
break;
case '/column.php':
echo '<div id="top3">';
break;
case '/funny.php':
echo '<div id="top3">';
break;
default:
echo '<div>';
}
?>

I'm not sure if this has anything to do with its problem. Thanks
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Old 04-08-2009, 10:56 PM Re: Include all files
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
echo $dir and post the output
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-10-2009, 01:20 PM Re: Include all files
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
Do you want me to do something like this?

PHP Code:
<?php
$dir 
str_replace('/'''__DIR__);
echo 
'' $dir;
switch(
$dir)
{
case 
'travel':
echo 
'<div id="top">';
break;
case 
'sports':
echo 
'<div id="top1">';
break;
case 
'politics':
echo 
'<div id="top2">';
break;
case 
'submit':
echo 
'<div id="top3">';
break;
case 
'links':
echo 
'<div id="top3">';
break;
case 
'column':
echo 
'<div id="top3">';
break;
case 
'funny':
echo 
'<div id="top3">';
break;
default:
echo 
'<div>';
}
?>
I tried this but it didn't work
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Old 04-11-2009, 05:22 AM Re: Include all files
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
He meant for you to echo the $dir variable and post the result here on the forum, so we may take a look at it.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 04-11-2009, 08:11 AM Re: Include all files
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
ok when I did this I got the result '__DIR__' at the top of the page
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Old 04-11-2009, 12:17 PM Re: Include all files
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
My mistake. __DIR__ only works in PHP 5.3.

Replace __DIR__ with dirname(__FILE__)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-11-2009, 12:50 PM Re: Include all files
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
Ok. I figured out the problem. I have the logo, and menu all in and external file that I include in every page. So when I echo dirname(__FILE__) It comes up with
'/usr/local/httpd/www.konetchreport.com/external' which is where I store the external file. Is there any way to get around this?
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Include all files
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.68785 seconds with 12 queries