Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Im trying to write the daily featured member out to a file, for specific reasons.

I thought it would be something like whats in BOLD: However I think it would append, not write as a string. Im also thinkin I would need a while loop maybe? Any ideas? I want to write out the featured member daily, so it would accumulate in a log file.

Quote
quote:

sub FeaturedMember {
$CurrentTime = time();
$vars_statistics{'FeaturedMemberDuration'} = $vars_statistics{'FeaturedMemberDuration'} * 3600;
if ( (($CurrentTime - $vars_statistics{'FeaturedMemberTime'}) > $vars_statistics{'FeaturedMemberDuration'}) && ($vars_statistics{'FeaturedMemberDuration'} != 0) ) {
srand;
$vars_statistics{'FeaturedMemberTime'} = $CurrentTime;
@the_members = &OpenFileAsArray("$vars_config{MembersPath}/memberslist.cgi");
my $x;
while (!$x) {
$x = $the_members[int (rand($StatsData{'TotalMembers'}-1) + 1)];
}
($StatsData{'FeaturedMember1'},$StatsData{'FeaturedMember2'}) = split(/|!!|/,$x);
chomp($StatsData{'FeaturedMember2'});
}
else {
$StatsData{'FeaturedMember2'} = "$vars_statistics{'FeaturedMember'}";
}

# get featured members public display name
if ((-e "$vars_config{MembersPath}/$StatsData{'FeaturedMember2'}.cgi") && ($StatsData{'FeaturedMember2'} ne '')) {
@user_profile = &OpenProfile("$StatsData{'FeaturedMember2'}");
chomp($user_profile[0]); chomp($user_profile[15]);
if ($user_profile[15] eq '') { $StatsData{'FeaturedMember1'} = "$user_profile[0]"; }
else { $StatsData{'FeaturedMember1'} = "$user_profile[15]"; }


}

$vars_statistics{'ShColSpan2'} = $ShColSpan2 if ($ShColSpan2);

$vars_statistics{'FeaturedMember'} = $StatsData{'FeaturedMember2'};
$vars_statistics{'FeaturedMemberDuration'} = int($vars_statistics{'FeaturedMemberDuration'} / 3600);

# write config to file!
&WriteHashToFile("$vars_config{VariablesPath}/vars_statistics.cgi", "vars_statistics", %vars_statistics);
&WriteFileAsString("$vars_config{NonCGIPath}/featured_member.txt",qq~Time: $GotTime{HyphenDate} $GotTime{Time}n$StatsData{'FeaturedMember1'}~);
}

Sponsored Links
Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
you could &OpenFileAsArray, an an entry, and &WriteFileAsArray

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Ok,

It looks like its being opened as an array here -->
Quote
quote:
@the_members = &OpenFileAsArray("$vars_config{MembersPath}/memberslist.cgi");
Im assuming I wouldnt wanna do that twice? In theory, all Im wanting to do is not only write it to vars_statistics.cgi, but also a readable text file, where it could be appended daily so I could see who the featured member was a week ago if I wanted too. Its for a contest Im doing...

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
that's a different file. You'd open the log file, add a line, and write it. no loop required

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Alright, I was thinking this

Quote
quote:

&AppendFileAsString("$vars_config{NonCGIPath}/featured_member.txt",qq~Time: $GotTime{HyphenDate}nFeatured Member For Today Is: $StatsData{'FeaturedMember1'}n~);

since Ill need to append each entry.

It works, however, somethings weird.

I have it set to switch every hour for now, and it just switched the featured memeber. This is what the file looks like though

quote:
[qb]
Time: 02-23-2005
Featured Member For Today Is: midmigurl
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: reimb1nb
Time: 02-23-2005
Featured Member For Today Is: potgirrl420
[/qb]
It keeps adding the same member multiple times. not sure why. Im lost doh

Sponsored Links
Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Think I figured it out. Had that line in the wrong location. I'll keep you posted if I have further problems.

Thanks wink

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Ian:

Last question, since I'm always looking for better things to do with mods.

Is there anyway we can add a line of code to the sub FeaturedMember function allowing only to pull featured members with 10+ posts?

This way it wont cycle through all registered members, but only ones with a specified number of posts? Thus your chances are higher of becoming the featured member.

Thus it would make my contest more exciting! wink

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
well all you'd do is open the file, and it the post count is under 10, do it again, until the person with 10 posts is selected

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
so maybe something like:

Quote
quote:

if ($user_profile[7] > 10) {
&AppendFileAsString("$vars_config{NonCGIPath}/featured_member.txt",qq~Date: $GotTime{HyphenDate} Time: $GotTime{Time}nFeatured

Member For Today Is: $StatsData{'FeaturedMember1'}, $StatsData{'FeaturedMember2'} nn~);
}
??

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
well, that would prevent a user from being a featured member from having 10 posts or less, but it'd also prevent having any featured member for at least the next (specified interval)

Sponsored Links
Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Right, which is what I wanted. If Im listening to you correctly.

I only want users to be the featured members who have at least 10+ posts. Every 24 hours.

So that makes sense then...

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Ya that doesnt work, duh! It'll still pick a random member, but only write to the text file if a user is chosen with 10+ posts.

Dam, I guess that isnt what i wanted. I actually want it to cycle through the database and look for users with only 10+ posts. lol

Im guessing I would use this while statement already in the function
Quote
quote:

while (!$x) {
$x = $the_members[int (rand($StatsData{'TotalMembers'}-1) + 1)];
}
Now what to add to it, Im not sure. or how..

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
well, you could always try to old standby


while($user_profile <= 10) {
&pick_new_number
&open_member;
}

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Right, but I need to adapt that to the already existing code. Above

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
I thought maybe like
Quote
quote:

while ((!$x) && ($user_profile[7] <= 10)) {
$x = $the_members[int (rand($StatsData{'TotalMembers'}-1) + 1)];
}

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Tried opening the users profile as an array as well, and still can't get it.

If someone can finish a working version for me with the code provided in the original post, Id be willing to give them a little cash for their troubles

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
*sees money*

Lemme try now

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
Untested
Code
sub FeaturedMember {
$CurrentTime = time();
$vars_statistics{'FeaturedMemberDuration'} = $vars_statistics{'FeaturedMemberDuration'} * 3600;
if ( (($CurrentTime - $vars_statistics{'FeaturedMemberTime'}) > $vars_statistics{'FeaturedMemberDuration'}) && ($vars_statistics{'FeaturedMemberDuration'} != 0) ) {
srand;
$vars_statistics{'FeaturedMemberTime'} = $CurrentTime;
@the_members = &OpenFileAsArray("$vars_config{MembersPath}/memberslist.cgi");
my $x;
my @user_profile;
$user_profile[7] = 5;

LOOP: while($user_profile[7] <= 10) {
$x = $the_members[int (rand($StatsData{'TotalMembers'}-1) + 1)];
if(&FileExists(qq~$vars_config{MembersPath}/$x.cgi~)) {
@user_profile = &OpenProfile($x);
} else {
next LOOP;
}
}

if ($user_profile[15] eq '') {
$StatsData{'FeaturedMember1'} = "$user_profile[0]";
} else {
$StatsData{'FeaturedMember1'} = "$user_profile[15]";
}

} else {
$StatsData{'FeaturedMember2'} = "$vars_statistics{'FeaturedMember'}";
}


$vars_statistics{'ShColSpan2'} = $ShColSpan2 if ($ShColSpan2);

$vars_statistics{'FeaturedMember'} = $StatsData{'FeaturedMember2'};
$vars_statistics{'FeaturedMemberDuration'} = int($vars_statistics{'FeaturedMemberDuration'} / 3600);

# write config to file!
&WriteHashToFile("$vars_config{VariablesPath}/vars_statistics.cgi", "vars_statistics", %vars_statistics);
&AppendFileAsString("$vars_config{NonCGIPath}/featured_member.txt",qq~Date: $GotTime{HyphenDate} Time: $GotTime{Time}nFeatured Member For Today Is: $StatsData{'FeaturedMember1'}, $StatsData{'FeaturedMember2'} nn~);
}

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
NOpe, that code just through my server in a loop. Now I gotta go chat my host and tell them to restart apache.

Dam.

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
That loop doesnt look right anyways. I want it to cycle through members with 10+ posts. not below 10

I'll let u know when i can upload more code and my server is online.


Update: Ok we're good again. I dont think I should risk loop issues though and my server going down again. I've already chatted my host twice about bringing it back up, lol

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
delete "srand;"

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
you pretty confident buddy?

oh and shouldnt it be user_profile[7] > 10 or no?

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
the way I have it says "do this while postcount is not greater than 10", which means it stops when it is greater than ten.

The way you suggested would prevent anyone with over ten posts from being featured.

Yes, I'm positive srand was causing the loop, as it prevented the random number from changing in the loop

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
Im sorry, maybe I wasnt clear then.

I wanted it written so that only users with 10+ posts are selected.

I'd hate to have a featured member be featured who has 0 posts. Whats the point in them winning the contest with 0 posts?

Which is why I was thinking only 10+ posts are featured members. Anything less than that IS NOT SELECTED wink

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
which is what I wrote **rage**

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
I dunno man, its not lookin good. My server doesnt seem to be doing to well with it. My server load keeps going up, and no featured member is displayed on the forum.

uggg sorry man

Joined: Sep 2001
Posts: 672
Member
Member
Offline
Joined: Sep 2001
Posts: 672
This thread is done. Cancelled project.


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Posts: 70
Joined: January 2007
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)