Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-24-2002, 10:18 PM   PM User | #1
Dalsor
New Coder

 
Join Date: Jul 2002
Location: Florida, USA
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Dalsor is an unknown quantity at this point
Include and arrays

Greetings.

Slight problem with pulling data from arrays stored in an included file. If I store the arrays in the same PHP file that is displaying the information, this works fine, but when I store the arrays in a seperate file and include() it, it can't find the data. I'm trying to keep all the arrays in one file by themselves to make changing things easier. Here's what I have come up with.

This is an excerpt from index.php
PHP Code:
<!--
Function: draw_body
Include: none
Purpose: Draw body text
//-->

<?php include('arrays.php'); ?>
<table width="100%" border="0" cellspacing="5" cellpadding="2">
  <tr>
  <td class="body2" height="100">
  <?php
  
for ( $i 0$i <= $warders$i++ )
  {
  echo 
$warArray[$i];
  echo 
"<br>";
  }
  
?>
  </td>
  </tr>
</table>
This is from arrays.php
PHP Code:
<?php
    $warArray
[0] = 'Asandir';
    
$warArray[1] = 'Caellach';
    
$warArray[2] = 'Caldamus';
    
$warArray[3] = 'Drizzt';
    
$warArray[4] = 'Flarn';
    
$warArray[5] = 'Jaryd';
    
$warArray[6] = 'Kale';
    
$warArray[7] = 'Kodel';
    
$warArray[8] = 'Kordac';
    
$warArray[9] = 'Lanth';
    
$warArray[10] = 'Makojin';
    
$warArray[11] = 'Mallagant';
    
$warArray[12] = 'Mica';
    
$warArray[13] = 'Narival';
    
$warArray[14] = 'Navvar';
    
$warArray[15] = 'Phostan';
    
$warArray[16] = 'Rance';
    
$warArray[17] = 'Ransard';
    
$warArray[18] = 'Rylas';

    
$warders count$warArray );
?>
Thanks in advance for any advice.
Dalsor is offline   Reply With Quote
Old 07-24-2002, 10:32 PM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,225
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
I just copied and pasted your coding and it ran just fine. Is that happening on your web hosts server or a development server you are running at home?
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 07-24-2002, 10:41 PM   PM User | #3
Dalsor
New Coder

 
Join Date: Jul 2002
Location: Florida, USA
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Dalsor is an unknown quantity at this point
It's happening on both my dev box and my server. Thinking it may be a global setting kind of thing?
Dalsor is offline   Reply With Quote
Old 07-24-2002, 11:04 PM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,225
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Possibly. Firepages my fellow mod may be able to shed some light on that area.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 07-24-2002, 11:15 PM   PM User | #5
Dalsor
New Coder

 
Join Date: Jul 2002
Location: Florida, USA
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Dalsor is an unknown quantity at this point
To avoid the possibility I might have overlooked something small ( entirely possible ), I tried adding this into the index.php

PHP Code:
<?php
    $success 
= @include('arrays.php');
    if ( !
$success )
    {
        echo 
"Could not include the arrays file. Trying another method.";
    }
    
$again = @include('/home/aww/public_html/tm/arrays.php');
    if ( !
$again )
    {
        echo 
"Could not include the arrays file again.";
    }
    
$useroot = @include( $DOCUMENT_ROOT 'arrays.php');
    if ( !
$useroot )
    {
        echo 
"Tried using the doc root that time. No go.";
    }
?>
I received all three errors on page load.
Dalsor is offline   Reply With Quote
Old 07-25-2002, 03:02 AM   PM User | #6
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,912
Thanks: 5
Thanked 80 Times in 79 Posts
firepages will become famous soon enough
sorry, but like Spooks I can see no reason why that code would not work under any circumstances unless there was a problem with the include path in the php.ini, in saying that I see you tried the absolute path which should work in anycase.

I used include './sample_array.txt';
but all of your methods should have worked with the possible exception of $DOCUMENT_ROOT which may give a misleading value in a script aliased directory (and is best now accessed via $_SERVER[DOCUMENT_ROOT]

try running this to see if your include path has anything strange in it

echo ini_get('include_path');
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is online now   Reply With Quote
Old 07-25-2002, 06:47 AM   PM User | #7
Dalsor
New Coder

 
Join Date: Jul 2002
Location: Florida, USA
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Dalsor is an unknown quantity at this point
It just returned the path to the php installation.
.:/usr/local/lib/php

It works by locating the arrays within the index.php, so I'll stick with that. Thanks for the help.
__________________
if ( bad && possible ) happen();
Sig re-written for faster processing...
Dalsor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 09:13 AM.


Advertisement
Log in to turn off these ads.