PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
LVZ
Forum Newbie
Posts: 5 Joined: Mon Oct 03, 2005 1:04 pm
Location: Las Vegas
Post
by LVZ » Mon Oct 03, 2005 1:14 pm
Ref:
http://mylvn.com/m2w/test.php and
http://mylvn.com/m2w-h.php
mylvn.com - ok - [admin@]
vegas215.com - three good users - one bad dup: [admin@]
my-las-vegas-neighborhood.com - one good user [bbs@] - four bad dups
Why do the recreated arrays seem to keep old data (user_ids) and just add new ones to it?
Code: Select all
<TABLE VALIGN=TOP BGCOLOR=#e0e0e0><TR VALIGN=TOP>
<?php
$domain = array ( "mylvn.com", "vegas215.com", "my-las-vegas-neighborhood.com" ) ; chdir ("../../mail");
foreach ($domain as $user_mail_dir) {
echo "<TD ALIGN=CENTER> " . $user_mail_dir . " <BR>\n";
echo "<select name='uname' class='SelectText' />";
echo "\n<option selected disabled>========";
$dh = opendir($user_mail_dir);
while (false !== ($filename = readdir($dh))) $files[] = $filename;
closedir($dh); sort($files);
foreach($files as $user_id) {
if ($user_id >= "A")
echo "\n<option value='" . $user_id . "@" . $user_mail_dir . "'>" . $user_id;
}
echo "\n</select>\n</TD>\n";
}
?>
</TR></TABLE>
Burrito : Please use Code: Select all
tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]posting php code in the forum[/url].[/size]
Last edited by
LVZ on Tue Oct 04, 2005 12:24 pm, edited 2 times in total.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Oct 03, 2005 6:41 pm
Do you mean the array $files ?
That'll be because you are not recreating it.
And you are missing braces on your while loop.
ruchit
Forum Commoner
Posts: 53 Joined: Mon Sep 26, 2005 6:03 am
Post
by ruchit » Tue Oct 04, 2005 3:08 am
Jenk.. the guy is not missing braces in while loop, he is only executing a single statement.
What the code misses out on is indenting.
pilau
Forum Regular
Posts: 594 Joined: Sat Jul 09, 2005 10:22 am
Location: Israel
Post
by pilau » Tue Oct 04, 2005 3:22 am
LVZ.. The only action performed on the $files array is sort()...
LVZ
Forum Newbie
Posts: 5 Joined: Mon Oct 03, 2005 1:04 pm
Location: Las Vegas
Post
by LVZ » Tue Oct 04, 2005 11:23 am
pilau wrote: LVZ.. The only action performed on the $files array is sort()...
When you take out the sort() as coded in the original example, the problem of cumulative $files array data remains.
BTW, the code snippet [ while ... readdir ] came from someone's comments at php.net
When I simplify the [readdir loop] code, eliminate sorting (and '$files' array), it works [but it is no longer sorted]
http://mylvn.com/m2w/test2.php [Success/Unsorted] -versus-
http://mylvn.com/m2w/test.php [Fails/Sorted]
Code: Select all
<TABLE VALIGN=TOP BGCOLOR=#e0e0e0><TR VALIGN=TOP>
<?php $domain = array ( "mylvn.com", "vegas215.com", "my-las-vegas-neighborhood.com" ) ;
chdir ("../../mail");
foreach ($domain as $user_mail_dir) {
echo "<TD ALIGN=CENTER> " . $user_mail_dir . " <BR>\n";
echo "<select name='uname' class='SelectText' />";
echo "\n<option selected disabled>========";
$dh = opendir($user_mail_dir);
while (false !== ($user_id = readdir($dh))) {
if ($user_id >= "A")
echo "\n<option value='" . $user_id . "@" . $user_mail_dir . "'>" . $user_id;
}
closedir($dh); /****************** SUCCESS BUT NOT SORTED ***********/
echo "\n</select>\n</TD>\n";
}
?>
</TR></TABLE>
LVZ
Forum Newbie
Posts: 5 Joined: Mon Oct 03, 2005 1:04 pm
Location: Las Vegas
Post
by LVZ » Tue Oct 04, 2005 12:31 pm
PROBLEM SOLVED - explicitly DECLARE array $files :::::::: working web utility -
http://mylvn.com/m2w-h.php
Does not work [within a loop]:
Code: Select all
$dh = opendir($user_mail_dir);
while (false !== ($filename = readdir($dh))) $files[] = $filename;
Solution:
Code: Select all
$files = array();
$dh = opendir($user_mail_dir);
while (false !== ($filename = readdir($dh))) $files[] = $filename;
I knew it had to be easy.