/    Sign up×
Community /Pin to ProfileBookmark

Using dirdisply() twice on the same page

I would like to use dirdisply() twice on the same page. It is actually in two different files that are included on the same page. Is this possible?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJul 31.2008 — Yes, If you are just calling the function, you can do this as many times as required depending on the function. But we wont know unless we see the function.

But if you are talking about redefining the function itself, so stop and errors, you could wrap it in [url=http://php.net/function_exists]function_exists[url]
Copy linkTweet thisAlerts:
@kudzugazetteauthorJul 31.2008 — Here is the code. They both are the same except for the directory they're listing.
[code=php]<?php
function DirDisply($data) {

$TrackDir=opendir("resources/facandstaff");

while ($file = readdir($TrackDir)) {

if ($file == "." || $file == "..") { }
else {
print "<li><a href='resources/facandstaffshow.php?page=$file'>$file</a>";

}

}
closedir($TrackDir);

return $data;
}

?><ul>
<?
@ DirDisply($data);
?>
</ul>[/code]
Copy linkTweet thisAlerts:
@SheldonJul 31.2008 — try this. Currently your proberly not getting any thing to show ?

[code=php]
<?php
// CHECK THAT FUNCTION IS NOT ALREADY DECLEARED
if(!function_exists("DirDisply")){
// START FUNCTION
function DirDisply($path){
// START OUTPUT
$data = "";
// OPEN DIRECTORY
$TrackDir=opendir($ptah);
// CREATE AN ARRAY OF FILES NOT TO SHOW
$badFiles = array(".","..");
// LOOP THROUGH DIRECTORY
while ($file = readdir($TrackDir)) {
// CHECK FILE NAME AGAIN BAD FILES.
if(!in_array($file, $badFiles)){
// DEFINE FILE AND LINK
$data .= "<li><a href='resources/facandstaffshow.php?page={$file}'>{$file}</a></li>n";
}
}
// CLOSE DIRECTORY
closedir($TrackDir);
// RETURN DATA
return $data;
}
}

?>
<ul>
<?php echo(DirDisply("resources/facandstaff/")); ?>
</ul>


<ul>
<?php echo(DirDisply("resources/this_dir/")); ?>
</ul>


<ul>
<?php echo(DirDisply("resources/that_dir/")); ?>
</ul>[/code]
Copy linkTweet thisAlerts:
@kudzugazetteauthorJul 31.2008 — Nifty. Thanks so much.
Copy linkTweet thisAlerts:
@kudzugazetteauthorJul 31.2008 — Sorry, one last thing.

Do you know if there's a way to get the listings in reverse alphabetical order? I tried using preg_find but I couldn't do both at the same time and the links didn't work.
Copy linkTweet thisAlerts:
@SheldonJul 31.2008 — you could build it in to an Array, then sort the Array.

Something using [url=http://php.net/sort]sort[/url] or [url=http://php.net/array_multisort]array_multisprt[/url] maybe.
×

Success!

Help @kudzugazette spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...