Re: [PHP] Re: How to understand this Warning?

2004-08-18 Thread Curt Zirzow
* Thus wrote Labunski with modifications:

?php
if ($handle = opendir('news')) {

  while (false !== ($topic = readdir($handle))) {

if ($topic != .  $topic != ..) {

  while (false !== ($topic = readdir($handle)))
  {
// this will never happen!
if($topic != .  $topic != ..)
{
  $topic=str_replace(.,,$topic);
  array_push($sortArray,$topic);
}
  }
  // We are at the end of all the files

  // snip all the other stuff.

// you're closing the file here so
// the next iteration of the loop it is no
// longer valid
closedir($handle);
  }
}
?



Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to understand this Warning?

2004-08-18 Thread Jason Wong
On Wednesday 18 August 2004 10:26, Labunski wrote:
 Hi,

  note the 2 in that message. You are prob. resetting the readdir()

 parameter in the script somewhere
 No, as far as I can see, I'm not resetting the readdir().. but..

  You loop twice throu the same dir?

 Yes I do.

Why? I don't understand your logic. Remove the outer while-loop, note that it 
encloses most of the code including the line:

  closedir($handle);

So on the second iteration of the outer while-loop $handle is gone and hence 
your error message.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Pure drivel tends to drive ordinary drivel off the TV screen.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: How to understand this Warning?

2004-08-17 Thread Hannes Magnusson
On Wed, 18 Aug 2004 02:54:35 +0300
[EMAIL PROTECTED] (Labunski) wrote:

 Hello,
 How to understand this warning?
 I thought maybe the directory name is incorrect, but it's fine.
 The Browser said..
 Warning: readdir(): 2 is not a valid Directory resource in
note the 2 in that message. You are prob. resetting the readdir() parameter in the 
script somewhere

 C:\xxx\x\news.php no line 78.
 
 
 ?php
  if ($handle = opendir('news')) {
 $sortArray=array();
 while (false !== ($topic = readdir($handle))) {  // this is line 78
 if ($topic != .  $topic != ..) {
 while (false !== ($topic = readdir($handle)))
 {
if($topic != .  $topic != ..)
{
 
You loop twice throu the same dir?

 - Hannes
 ..etc. etc.
 I posted just a first part (beginning) of the code, so that it were easier
 to understand.
 
 Sorry for my bad English,
 Thank you very much,
 Lab.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: How to understand this Warning?

2004-08-17 Thread Labunski
Hi,
 note the 2 in that message. You are prob. resetting the readdir()
parameter in the script somewhere
No, as far as I can see, I'm not resetting the readdir().. but..

 You loop twice throu the same dir?
Yes I do.

Here is whole script:

 ?php
 if ($handle = opendir('news')) {

$sortArray=array();

while (false !== ($topic = readdir($handle))) {
if ($topic != .  $topic != ..) {

while (false !== ($topic = readdir($handle)))
{
   if($topic != .  $topic != ..)
   {
  $topic=str_replace(.,,$topic);
  array_push($sortArray,$topic);
   }
}
sort($sortArray);
reset($sortArray);
$topicArray=array();
foreach($sortArray as $folder)
{
   $year=substr($folder,4,0);
   $month=substr($folder,2,4);
   $day=substr($folder,2,6);

   array_push($topicArray,$year...$month...$day);
}

foreach($topicArray as $topic)
{

 // this part reads text from the text file
   $path = news/.$topic./intro.txt;
   $file = file($path);
   foreach($file as $value ) {
   $value = preg_replace(/\n/, br, $value);
$intro_text .= $value;
   }
$intro_picture = $topic./start.jpg;
$date = $topic;
 echo 
 tr
 td width='476' valign='top'table width='100%' border='0'
 cellpadding='0' cellspacing='0' class='raksti_bot'
  !--DWLayoutTable--
 tr
  td width='100' height='100' align='center' valign='middle'
 class='raksti_both_ver'
  img src='news/.$intro_picture.' width='90' height='90'/td
  td width='10'nbsp;/td
  td width='281' valign='top'br.$intro_text.br/td
  td width='10'nbsp;/td
  td width='75' align='center' valign='middle'
 class='raksti_both_ver'.$date./td
 /tr
 /table/td
 /tr
  \n;

 unset($intro_text);
}
}
closedir($handle);
 }
 }
 ?


Lab.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php