Gossamer Forum
Home : Products : DBMan : Customization :

Top Ten by Gender for Johnsonny

Quote Reply
Top Ten by Gender for Johnsonny
I was working on your mod and I had some questions.

What is the name of your gender field?

Is there a radio button defined for the field? What are the options?

When you print out your top ten page, do you want both genders to be listed, side by side?



JPD
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Thanks a lot JPDeni!!!!
The gender field is called "Sex"..I am using sub build_fancy_select_field for the Sex option "Male" or "Female" ( that is a drop down menu)..
Yeah...I want both genders to be listed, side by side...That should be fine..

Thanks a lot!


Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
You're using the "fancy" select field? I need to know what values will be actually in the database.


JPD
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Thanks again..
I am using "1" for "male and "2" for "female" ...

:)


Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
I would never have guessed that! Smile

I'll get back to work on it tonight.

JPD
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
I think I've got it.

This is the whole mod, not just changes you'll need to make.

Create two subdirectories in your $counter_dir, named 1 and 2.

Code:
###############################################################
# default.cfg
#-------------------------------------------------------------
# Add the following to your .cfg file:
###############################################################

### In the # File and URL's section add:

# Full Path and File name of the record view count directory.
$counter_dir = $db_script_path . "/temp";

### After $auth_logoff = "http://www.yourdomain.com"; add:

# How many seconds to remove the old ip addresses for record view count?
# 3600 - One Hour (Recomended)
$ipupdate = "3600"; ### Added for time interval



###############################################################
# html.pl #
#-------------------------------------------------------------#
# In 'sub html_record' (or 'sub html_record_long', if you're #
# using the short/long display mod): #
###############################################################

### After

my (%rec) = @_;


### add
&top10($rec{$db_key},$rec{'Sex'});

sub html_topten {
#-------------------------------------------------------------

&html_print_headers;
print qq|
<html>
<head><title>$html_title: top Ten Records.</title></head>
<BODY>
header html code goes here
|;
print "<table><tr>";
for ($j=1;$j<3 ;++$j) {
undef (@files,%count,@top_ten,$toparray,$toplist);
opendir (TEMPDIR, "$counter_dir/$j");
@files = readdir(TEMPDIR); # Read in list of files in directory..
closedir (TEMPDIR);
FILE: foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
open (COUNTER, "<$counter_dir/$j/$file");
$count{$file} = int(<COUNTER> );
close COUNTER;
}
foreach $key (sort {$count{$b} <=> $count{$a} } keys %count) { push (@top_ten,$key); }
for ($i=0;$i<10 ;$i++) {
$toparray .= "$top_ten[$i],";
}
chop $toparray;
print "<td>";
foreach my $toplist (split(/,/,$toparray)) {
&html_record(&get_record($toplist)); ## See below if you're using short/long display mod
}
print "</td>";
}
print "</tr></table>";
print qq|footer html code goes here|;
&html_footer;
print qq|</body></html>|;
}

#### For short/long display, use the following, and change $rec{'FieldName'} to match your database.

%rec = (&get_record($toplist));
print qq|
<a href="$db_script_link_url&$db_key=$rec{$db_key}&view_records=1&ww=1">$rec{'FieldName'}</a><BR>
|;



### In 'sub html_footer', add

print qq!|<A HREF="$db_script_link_url&topten=1">top Ten</A> ! if ($per_view);



###############################################################
# db.cgi #
#-------------------------------------------------------------#
# Delete (or comment out) this line in sub get_record: #
###############################################################

($restricted = 1) if ($auth_modify_own and !$per_admin);



### In 'sub main', after
if ($in{'add_form'}) { if ($per_add) { &html_add_form; } else { &html_unauth; } }
### add
elsif ($in{'topten'}) { if ($per_view) { &html_topten; } else { &html_unauth; } }


sub top10 {
#-----------------------------------------------------------
my ($key) = $_[0];
my ($gender) = $_[1];
$key =~ s/<?.B>//g;
$gender =~ s/<?.B>//g;
$iptime = time();
$remote = $ENV{'REMOTE_ADDR'};
$cheat = 0;
if (-e "$counter_dir/iplog.txt") {
open (iplog, "+<$counter_dir/iplog.txt");
if ($db_use_flock) { flock(iplog, 2); }
@ipdata = <iplog>;
seek (iplog, 0, 0);
truncate (iplog,0);
foreach $log (@ipdata) {
@ips = split(/\|/, $log);
$iptotal = $iptime - $ips[1];
if (($ips[0] == $remote) && ($ips[2] == $key) && ($iptotal < $ipupdate)) { $cheat = 1; }
if ($iptotal < $ipupdate) { print iplog "$ips[0]|$ips[1]|$ips[2]\n"; }
}
unless ($cheat) { print iplog "$remote|$iptime|$db_key\n"; }
close (iplog);
}
else {
open(newip, ">$counter_dir/iplog.txt");
print newip "$remote|$iptime|$key\n";
close (newip);
}
if (!$cheat) {
open (COUNT, "$counter_dir/$gender/$key");
if ($db_use_flock) { flock(COUNT, 2); }
$countup = <COUNT>;
$countup++;
close COUNT;
open (COUNT, ">$counter_dir/$gender/$key");
if ($db_use_flock) { flock(COUNT, 2); }
print COUNT $countup;
close COUNT;
}
else {
open (COUNT, "<$counter_dir/$gender/$key");
if ($db_use_flock) { flock(COUNT, 2); }
$countup = <COUNT>;
close COUNT;
}
}
JPD
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Wonderful man!!
Thanks a lot JPDeni..thanks for all the time you did it for me. :)
I will try it and tell you how it works

Thanks again here....
:)

Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Hi again JPDeni,

I just tried it but it is not working. It only shows top ten hits record of "male" three times but it didnt show top ten hits record of "femlae".

I checked up the subdirectories "1" and "2". All of male record is in "1" and all of female record is i "2". That should work fine.

Could you please help me?

Thanks a lot

Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
I will have to create a database to work on this, then. Give me a little time.


JPD
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Thanks a lot,JPDeni

I am looking forward to hearing any good news from you

:)


Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
I got it. (I did have to create my own database, though.)

Change

undef (@files,%count,@top_ten,$toparray,$toplist);

to


undef @files;
undef %count;
undef @top_ten;
undef $toparray;
undef $toplist;


I had the right idea, but I now know that you can't "undef" more than one variable at a time.


JPD
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Cool....IT does work well!!!

Thanks JPDeni,thanks for all the time you have spent for this mod!!

:)

Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Glad I could help. It does feel good to have something working correctly! Smile

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Hi!

I would like to use the same mod. I tried to use the one you sent to this thread but didn't work, perhaps because I use radio fields?

I'm using radio fields and the values are 'Erkek' and 'Kadin'.

I'll be very happy JP if you find time to help me with that.
btw, how do you manage to do that? I mean answering so many people and solving so many problems so quickly?

Are the days 40 hours or something at where you live? :)

Thanks!

Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
In Reply To:
Are the days 40 hours or something at where you live? :)
Don't I wish! Smile

Basically, I don't do much of anything else. Although I did just get a couple of new programs that I'd like to learn about. Someday!

The reason this doesn't work for you is that you have different values for the gender field. Let's see if I can work it out.

Okay. I have written a mod file that should be general enough for anyone to use for anything they want. Please give it a try. It's at http://www.jpdeni.com/...Mods/top_ten_gen.txt. If it works for you, I'll post it in the Resource Center.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Thanks a lot Carol!!!

It worked, with one small change:

in sub html_topten, change

for ($j=1;$j<=$#top_ten_values_array ;++$j)

#to

for ($j=0;$j<=$#top_ten_values_array ;++$j)

I tried to see the problem myself (kind of training :-) ), so it took a day to find out that it was "j=1". I'm sure you would solve the problem in 10 sec.?

But, you know, it's good to encourage rookies. So you can reply me lying "Goush! I would never solve that problem without your help! What a talent you have! Go on Ozgur!" lol

Ok, enough nonsense...

Thanks JPDeni

Quote Reply
Re: Top Ten by Gender for Johnsonny In reply to
Goush! I would never solve that problem without your help! What a talent you have! Go on Ozgur!

Laugh

You are absolutely right, though. I'll go change that right now.....There. All better now.

Thanks much for being willing to test it out. I rely on people to be my test subjects because creating databases just to test the mods can take longer than writing them.

I'm really glad it worked for you.


JPD
http://www.jpdeni.com/dbman/