Jump to content

Its something simple I'm sure


proggR

Recommended Posts

I've been boggled by this for a few days now and I've just been putting it off but I need it fixed.

I'm reading in a text file thats path is saved as $course. This will get checked to see if its a valid file and if it is its supposed to open it up and read the contents into an array.

It loops through a while loop as long as it hasn't reached the end of the file. For redundancy I have an if statement within that loop to also check if its the end of the file and if its not, it read the line, and if it is, it closes the file. If none of this has been true it returns a page called missing.html to be displayed.

The problem is that it appears that somehow the array gets one more index then it should be getting because where I'm supposed to have 3 posts, I have 3 posts and an error saying it couldn't include '' (blank).

The exact error is:

Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;C:\php5\pear') in E:\Program Files\Apache Group\Apache2\htdocs\class.php on line 104

 

which refers to this section:

<?php
//prints all the posts on page

foreach ($post[$page] as $value) 
{ 

include($value);
echo "<a href =\"".$value."\">".$value."</a><br>";
}
?>

 

The reason it has $page is because I also have this section that determines what page you're viewing and splits the first array ($item) into a 2d array with 5 articles per page

 

<?php
//determimes page
if (isset($_GET["page"])){
$page = $_GET["page"];
}
else{
$page=0;
}

//end determining page

$post= array_chunk($item,5);// splits the posts into pages with 5 posts per page

?>

 

This is the main section that I believe is the problem but I'm not sure. If anyone sees anything I've missed thats causing this extra index value please let me know. I have two sections of my site that need this to work. Thanks in advance

 

<?php
//assigns each post to a one dimensional array which will be split into a 2d array later
$counter = 0;
if(is_file($course)){
$fh = fopen($course,'rt');


While(!feof($fh)){
if(!feof($fh)) {
$buffer = fgets($fh);
$item[$counter] = trim($buffer);
$counter = $counter+1;	
}

else{

fclose($fh);	

    }

}

}
else
{
$item[0]="missing.html";
}



//end the reading of the file
?>

Link to comment
Share on other sites

I had something similar to that too. Changing the code I have with your example gave me an infinite loop though for some reason. I'll keep trying that check and see if I just did something wrong though.

Any other ideas?

 

*edit* ok no more infinite loop, but still the extra index value. Do you think maybe its happening with the array_chunk() or my foreach() sections? The logic of that first section (which I've posted last) seems right to me and has redundant checks to make sure it is. I'm at a loss.

Link to comment
Share on other sites

But how would that change any of this? None of these are declared within a function. I'm not calling any functions that aren't from the PHP library. I haven't got around to organizing my code into my own functions so they're all declared outside of variables.

Link to comment
Share on other sites

But how would that change any of this? None of these are declared within a function. I'm not calling any functions that aren't from the PHP library. I haven't got around to organizing my code into my own functions so they're all declared outside of variables.

 

if you include pear into a function you can only use it inside that function, at a lower level this is teh arangment of the memory and code that physicaly restricts it when u declare a function it has a memory space outside of wich nothis is recognised, instead from outside you can pip info into its signiture paramiters but u cant talk to it otherwise, so if u include pear into a function you can only use it inside that functuion.

Link to comment
Share on other sites

I don't know what pear is. The C:.../pear path it has as the include_path has nothing to do with any variables I've created. C: is my Vista partition, I'm working on E:. All I'm including is the variables from the array that hold the value of the path to files I'm using. The three that actually exist work fine, its just got this 4th that it shouldn't have.

Link to comment
Share on other sites

Those are the only scripts. The rest is just HTML code. I'll post the whole file when I'm at home and have it again.

I ended up putting a check in my foreach() that checked before it included and if it was just "" as a value it would include my standard "Oops, this file isn't there" file. I was excited that it worked except when I tested it, I had 5 posts and this was the 6th so it was on its own page, but then I deleted the posts and only had 2 and it would come up with that message on the same page as the other posts. So now I have to think again. Its the last thing I have left to do except security so I hope I can resolve it soon.

I'll post the whole code tonight and see if anyone can spot something I'm missing.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.