Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
dezina
Theme Guru


Joined: Dec 26, 2002
Posts: 57
Location: UK

PostPosted: Wed Jan 14, 2004 8:23 am Reply with quote

Code:
<?php

if (eregi("block-Pages.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

function directory($result)
     {
     $handle=opendir("./users");
     while ($file = readdir($handle)) {
     if ($file == "." || $file == ".." || $file== "_notes" || $file== "htmlarea" || $file== "index.php") { } else { print "<a href=users/$file>$file</a><br>\n"; }
     }
     closedir($handle);

return $result;
}
$content .= "Select the users home page:";
echo directory($result);
?>


Works, but the result is shown above Block Title, not in actual Block.
Any advice or help gratefully received . TIA
 
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Wed Jan 14, 2004 9:26 am Reply with quote

You can't echo in a block. All output of a block must be handled through the $content variable. Try something like $content .= directory($result);

I also notice that you are passing a value ($result) to the function but their is nor $result in the block code outside of the function. Could just be that you don't have all the code. Just an observation Smile
 
View user's profile Send private message
dezina
PostPosted: Wed Jan 14, 2004 9:48 am Reply with quote

Thanks Raven, I've obviously not coded correctly.Am trying to list folders that reside in a directory on server, and the blocks gives links to those folder. When clicked, the user should be taken to index.html file in each of the folders, depending on which link clicked. Any advice here on how I go about this please? TIA
 
Raven
PostPosted: Wed Jan 14, 2004 10:03 am Reply with quote

I haven't tested this, but you might try
Code:
<?php 

if (eregi("block-Pages.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

function directory()
     {
     global $content;
     $handle=opendir("./users");
     while ($file = readdir($handle)) {
     if ($file == "." || $file == ".." || $file== "_notes" || $file== "htmlarea" || $file== "index.php") { } else { $content .= "<a href=users/$file>$file</a><br>\n"; }
     }
     closedir($handle);
}
$content = "Select the users home page:<br />".$content;
?>
 
dezina
PostPosted: Wed Jan 14, 2004 11:28 am Reply with quote

Raven, regret no joy, but thank you very much for trying. Wink
 
Raven
PostPosted: Wed Jan 14, 2004 11:37 am Reply with quote

Are you sure the fucntion is working correctly? Try inserting
echo $content;
after the closedir($handle); statement and see if it prints anything above the block. If not, then the function is not working.
 
dezina
PostPosted: Wed Jan 14, 2004 11:56 am Reply with quote

My original coding produces the desired result, BUT it prints the link/s ABOVE the Block title, and not in the actual block, so am assuming that function code is working correctly, just that my code is putting it outside the actual block Confused
 
Raven
PostPosted: Wed Jan 14, 2004 12:50 pm Reply with quote

But, I need you to try what I suggested to help me in debugging it. Thanks.
 
dezina
PostPosted: Thu Jan 15, 2004 4:17 am Reply with quote

Understood.
Code:
<?php

if (eregi("block-Pages.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

function directory($result)
     {
     $handle=opendir("./users");
     while ($file = readdir($handle)) {
     if ($file == "." || $file == ".." || $file== "_notes" || $file== "htmlarea" || $file== "index.php") { } else { print "<a href=users/$file>$file</a><br>\n"; }
     }
     closedir($handle);
echo $content;
return $result;
}
$content .= "Select the users home page:";
$content .= directory($result);
?>


Produces...
Link
Link
Then: Block Title(PAGES)
Then: Select the users home page:
 
Raven
PostPosted: Thu Jan 15, 2004 4:50 am Reply with quote

First, a question. Did you use the global $content statment in my code I told you to try up above?
Code:
<?php 

if (eregi("block-Pages.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

function directory()
     {
     global $content;
     $handle=opendir("./users");
     while ($file = readdir($handle)) {
     if ($file == "." || $file == ".." || $file== "_notes" || $file== "htmlarea" || $file== "index.php") { } else { $content .= "<a href=users/$file>$file</a><br>\n"; }
     }
     closedir($handle);
}
$content = "Select the users home page:<br />".$content;
?>


If that doesn't work, then this should
Code:
<?php 

if (eregi("block-Pages.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

function directory($result)
     {
     $content = "";
     $handle=opendir("./users");
     while ($file = readdir($handle)) {
     if ($file == "." || $file == ".." || $file== "_notes" || $file== "htmlarea" || $file== "index.php") { } else { $content .=  "<a href=\"users/$file\">$file</a><br>\n"; }
     }
     closedir($handle);
return $content;
}
$content .= "Select the users home page:<br />";
$content .= directory($result);
?>
 
dezina
PostPosted: Thu Jan 15, 2004 4:58 am Reply with quote

Very Happy Thank you so much Raven, Second Version works just fine
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©