Gossamer Forum
Home : Products : DBMan : Customization :

Some Odd Questions :)

(Page 2 of 2)
> >
Quote Reply
Re: Some Odd Questions :) In reply to
Carol,

Ran across something a bit tricky...I'm sure you already know this, but with all these renamed files and everything in the same directory, I can't currently run the script...meaning I can't customize any of this yet and see whether or not it works.

Just curious, see ya tommorrow! Smile

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
Did I forget to include "&add-form=1"? Sorry 'bout that. Glad you caught it, though.

Yes, the HittingID and the PlayerID will be different. You will have multiple records in the Hitting database for each PlayerID, right? The HittingID field is really meaningless, except that it gives a unique value for each record.

My suggestion is that you hide the HittingID and PlayerID once we get all of this done. Leave it for now so you can keep track of stuff.

Okay. Now we need to show the hitting stats with the players stats.

Add some hitting stats for one of your players. (I would have done it, but I don't have any idea of the logical range of numbers to put in. Smile ) Add at least two hitting records for the player.

Next, add three subroutines to your db.cgi file, each with the following format

Code:
sub switch_to_database name {
#-----------------------------------
$cols = 'all of your fields for the database, separated by commas';
@db_cols = split /,/,$cols;
$db_file_name = $db_script_path . "/name of the database file.db";
$db_key_pos = the number of the key field for this database;
}

Be sure that you fill in all of the italicized parts above with the appropriate values for each database.

In the subroutines for your hitting and pitching databases, add

Code:
$$db_sort{'Year'} = 'numer';

since you are going to be sorting those search results by the year.
This won't do anything directly that you can check out, but add the code and then go back to the database again to make sure you don't have any syntax errors.

Then I'll show you how to use it. Smile


------------------
JPD








[This message has been edited by JPDeni (edited April 30, 2000).]
Quote Reply
Re: Some Odd Questions :) In reply to
Carol,

Woohoo! No syntax errors! Smile I added hitting stats from 1998 and 1999 for Nomar Garciaparra (PlayerID: 2 - sure some name he's got, huh?)...db.cgi working fine, no syntax error, just to make sure I got it right, here are the 3 subroutines...

Code:
sub switch_to_players {
#-----------------------------------
$cols = 'PlayerID, Name, Position, Team, Jersey, Height, Weight, Batting, Throwing, Birthdate';
@db_cols = split /,/,$cols;
$db_file_name = $db_script_path . "/players.db";
$db_key_pos = 0;
}




sub switch_to_hitting {
#-----------------------------------
$cols = 'HittingID, PlayerID, Year, Gms, ABs, Runs, Hits, HRs, RBI, BBs, SOs, SBs, AVG';
@db_cols = split /,/,$cols;
$db_file_name = $db_script_path . "/hitting.db";
$db_key_pos = 0;
$$db_sort{'Year'} = 'numer';
}




sub switch_to_pitching {
#-----------------------------------
$cols = 'PitchingID, PlayerID, Year, Gms, IP, W, L, SOs, BBs, CGs, SHO, Svs, ERA';
@db_cols = split /,/,$cols;
$db_file_name = $db_script_path . "/pitching.db";
$db_key_pos = 0;
$$db_sort{'Year'} = 'numer';
}

(sorry for always posting code like this, it's partially so I can make sure I havn't screwed up! Smile)

Oh, also...I was wondering, will the link to add hitting stats be able to be adjusted to add pitching stats depending on maybe some hidden field designating a player as a pitcher rather than a hitter? Or will we be like setting up a whole other database just like this one for the pitchers?

Oh and PLEASE don't apologize for forgetting that tiny piece of the URL...I got a kick out of figuring it out...I really hope that someday I'll know enough about all of this to help others as you people like you and Eliot have helped me.

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
Oh one more thing, yes you're correct, most players will have more than just one year's worth of stats...as in more than one record in the stats database (be it pitching or hitting)...however SOME will only have one record...rookies and such Smile

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
I just noticed that there appear to be spaces in the $cols definition in your subroutines. There should not be a comma-space between them, only a comma:

Code:
$cols = 'PlayerID,Name,Position,Team,Jersey,Height,Weight,Batting,Throwing,Birthdate';

This is pretty important. Make sure you take out the spaces in all three subroutines.

Once you get that fixed, it's time to get going. Smile

In players_html.pl, sub html_record_long, after you print out your record, add

Code:
&switch_to_hitting;
undef %in;
$rec{'PlayerID'} =~ s/<?.B>//g;
$in{'PlayerID'} = $rec{'PlayerID'};
$in{'sb'} = 2;
$in{'mh'} = 100;
my ($status2,@hits2) = &query("view");
if ($status2 eq "ok") {
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);
print "<table><tr>";
for ($i=2;$i<=$#db_cols;++$i) {
print "<td>$db_cols[$i]</td>";
}
print "</tr>";
for (0 .. $numhits2 - 1) {
%rec2 = &array_to_hash($_, @hits2);
print "<tr>";
for ($i=2;$i<=$#db_cols;++$i) {
print "<td>$rec2{$db_cols[$i]}</td>";
}
print "</tr>";
}
print "</table>";
}
&switch_to_players;

This should print out a table, with headings, for each year for which the player has an entry in the hitting db. (We'll worry about making it fancy later. Right now we just want it to work. Smile )

I'm glad that you posted the subroutines. For one thing, I was able to catch a potential problem. For another, it's good to see the progress.

For the pitchers, we can do a couple of different things. You can set up a link just like the hitting link to appear on all records if you want. (You would just use the ones that apply to the player.) Or we could base it on the value of the Position field in the players db. Pitchers usually stay as pitchers, don't they?

Okay. Once you fix the subroutines and add the code to players_html.pl, fire 'er up and take a look. First look at Garciaparra's record (that is a mouthful! Smile) and see if his hitting stats show up. Then look at somebody else's that doesn't have anything in the database and see what happens. (You shouldn't see anything below the basic record.)


------------------
JPD






Quote Reply
Re: Some Odd Questions :) In reply to
Carol,

Yeah pitchers usually stay as pitchers, so a link or something would be fine, doesn't make a big difference to me, I'll probably be the only one adding to this DB anyway Smile

I took out the spaces and added the code, but got this error message:

Code:
CGI ERROR==========================================
Error Message : fatal error: Undefined subroutine &main::switch_to_hitting called at ./players_html.pl line 213.
Script Location : /usr6/home/warningt/public_html/cgi-bin/stats/db.cgi
Perl Version : 5.00503Setup File : players.cfg
User ID : adminSession ID : admin.95718586620782

Here's my current subroutine..

Code:
sub html_record_long {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_; # Load any defaults to put in the VALUE field.
if ($db_total_hits > 1) {
# create links to previous and next records
$next_url = $ENV{'QUERY_STRING'};
$next_url =~ s/\&nh=\d+//;
$next_hit = $nh + 1;
$prev_hit = $nh - 1;
if ($prev_hit) {
$previous = qq~<a href="$db_script_url?$next_url&nh=$prev_hit"><$font>Previous</font></a>~;
}
else { $previous = " "; }
if ($next_hit <= $db_total_hits) {
$next = qq~<a href="$db_script_url?$next_url&nh=$next_hit"><$font>Next</font></a>~;
}
else { $next = " "; }
# create link back to short display
$list_url = $next_url;
$list_url =~ s/\&mh=\d+//;
$mh = $db_max_hits;
$lh = int(($nh-1)/$mh) + 1;
$list = qq~<a href="$db_script_url?$list_url&nh=$lh"><$font>Back to record list</font></a>~;
# print out the links
print qq|
<table width=100%>
<tr><td width=50%>$previous</td>
<td width=50% align=right>$next</td></tr>
<tr><td colspan=2 align=center>$list</td></tr>
<tr><td colspan=2 align=center><$font>Record $nh of $db_total_hits</font></table>
|;
}
($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';



print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">|;


if ($per_add) {
print qq|<TR><TD ALIGN="Right" VALIGN="TOP"></TD><a href="$db_script_url?db=hitting&uid=$db_uid&add_form=1&PlayerID=$rec{'PlayerID'}">
Add Hitting Statistics for $rec{'Name'}</a></TD></TR>
|;
}

if ($per_admin) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>PlayerID:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'PlayerID'}</Font></TD></TR>
|;
}
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Name:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Name'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Position:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Position'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Team:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Team'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Jersey:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Jersey'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Height:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Height'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Weight:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Weight'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Batting:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Batting'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Throwing:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Throwing'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Birthdate:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Birthdate'}</Font></TD></TR>
</TABLE>
|;

&switch_to_hitting;
undef %in;
$rec{'PlayerID'} =~ s/<?.B>//g;
$in{'PlayerID'} = $rec{'PlayerID'};
$in{'sb'} = 2;
$in{'mh'} = 100;
my ($status2,@hits2) = &query("view");
if ($status2 eq "ok") {
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);
print "<table><tr>";
for ($i=2;$i<=$#db_cols;++$i) {
print "<td>$db_cols[$i]</td>";
}
print "</tr>";
for (0 .. $numhits2 - 1) {
%rec2 = &array_to_hash($_, @hits2);
print "<tr>";
for ($i=2;$i<=$#db_cols;++$i) {
print "<td>$rec2{$db_cols[$i]}</td>";
}
print "</tr>";
}
print "</table>";
}
&switch_to_players;


}

Is the new code in the wrong place?

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
Nevermind! Problem solved! the $db_sort command in the switch_to subroutines had an extra "$" in front of them...as in, "$$db_sort"...I just thought this was part of the code...and DON'T apologize! Once again I like not feeling totally helpless.

Stats look good, in a plain table, sorted perfectly...oldest year last, woohoo! Smile Pitching is the next step? Smile

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
Okay. I won't apologize. At least I won't write it here. Smile

Yep. Pitching's next.

Since pitchers stay pitchers, you can probably just show the link to the pitching form for pitchers. (I'm getting thirsty! Smile

You currently have

Code:
if ($per_add) {
print qq|<a href="$db_script_url?db=htting&uid=$db_uid&PlayerID=$rec{'PlayerID'}&add_form=1">
Add hitting statistics for this player</a>
|;
}

Change this to

Code:
if ($per_add) {
print qq|<a href="$db_script_url?db=htting&uid=$db_uid&PlayerID=$rec{'PlayerID'}&add_form=1">
Add hitting statistics for this player</a>
|;
if ($rec{'Position'} eq 'Pitcher') {
print qq|<a href="$db_script_url?db=pitching&uid=$db_uid&PlayerID=$rec{'PlayerID'}&add_form=1">
Add pitching statistics for this player</a>
|;
}

}

Notice that I added an "if" for the Position field to be "Pitcher."

Add some pitching stats for a player.

Then add the following after the hitting table:

Code:
&switch_to_pitching;
my ($status3,@hits3) = &query("view");
if ($status3 eq "ok") {
my ($numhits3) = ($#hits3+1) / ($#db_cols+1);
print "<table><tr>";
for ($i=2;$i<=$#db_cols;++$i) {
print "<td>$db_cols[$i]</td>";
}
print "</tr>";
for (0 .. $numhits3 - 1) {
%rec3 = &array_to_hash($_, @hits3);
print "<tr>";
for ($i=2;$i<=$#db_cols;++$i) {
print "<td>$rec3{$db_cols[$i]}</td>";
}
print "</tr>";
}
print "</table>";
}
&switch_to_players;


Then give 'er a try. Do some players have both pitching stats and hitting stats? It would be great if you tried it with somebody who had both, just to make sure everything was working right.

You might notice that there aren't as many lines in this code as in the last one. That's because all of the "$in" variables are already set. No point in undefining them and setting them again.

I just went to your site and took a look. This is exciting!! Smile

I won't be back on for several hours. I still haven't been to bed yet. I'm going now.


------------------
JPD






Quote Reply
Re: Some Odd Questions :) In reply to
Carol,

I set the link up and made a record for a pitcher named "Randy Johnson"...the link to add pitching stats didn't fill in the PlayerID field by default...I looked at the code but couldn't figure it out...

...I filled it in manually and added stats from 1999 and 1998, and it works just fine! Displayed just like the hitting stats, so everything is functional there...!!! Smile

Man, get yourself some sleep..3AM? I'm a night owl and I'm rarely up that late...

Sorry to say no players right now really have both pitching and hitting stats...there ARE pitchers who have to bat occasionally, but those arn't usually of much interest to anyone.

Wow, I can't believe it, in only a couple of days everything is functional! Except for that one little bug I mentioned earlier this thing freakin works already! Amazing! Smile

I'll backup my files and make the format a little bit nicer...just some basics (can't help myself, I'm very picky Smile)...

Ya know during the baseball offseason before this current season started I created about 650 player profiles sort of like these...they had one year's worth of stats and the basic height, weight, etc...I'd spend a couple of hours on it every day and I got all 650 or so done in a little over a month...hurts my head to think of how much time something like this could have saved me...!

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
Carol,

Keep sleeping! You need your rest! Smile

I've made the page look a little bit more like the rest of my site...but not all the way, wouldn't make sense until everything technical is out of the way.

Just thought you'd like to know I took out the "Name" field and replaced it with two fields: "First" and "Last"...this gives me a little more flexibility...so now when you click "List All" the names are listed like this:

Garciaparra, Nomar - Boston Red Sox

That leads me to something else: would it be possible to sort the "List All" command? As in the line above would be with all the other "G"s?

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
I forgot about the change you need to make to the pitching_html.pl file.

In sub html_record_form, after

my (%rec) = @_;

add

$rec{'PlayerID'} = $in{'PlayerID'};

(I actually know who Randy Johnson is. Smile )

Since everything is working, you can do a little bit to make it work better.

You can create a link in sub html_add_success in both the hitting_html.pl and pitching_html.pl files that will send you back to the original player record.

In both files, after

&html_record(&get_record($in{$db_key}))

add

Code:
print qq|
<a href="$db_script_url?db=players&uid=$db_uid&PlayerID=$in{'PlayerID'}&ww=1&view_records=1">
Return to player record</a>
|;

Or you could just automatically go to the player record after the stat for a year is added. If you wanted to do this, replace the entire sub html_add success with

Code:
print "Location: $db_script_url?db=players&uid=$db_uid&PlayerID=$in{'PlayerID'}&ww=1&view_records=1\n\n"

If you would rather not have the link for adding hitting stats to a pitcher, you can change

Code:
if ($per_add) {
print qq|<a href="$db_script_url?db=htting&uid=$db_uid&PlayerID=$rec{'PlayerID'}&add_form=1">
Add hitting statistics for this player</a>
|;
if ($rec{'Position'} eq 'Pitcher') {
print qq|<a href="$db_script_url?db=pitching&uid=$db_uid&PlayerID=$rec{'PlayerID'}&add_form=1">
Add pitching statistics for this player</a>
|;
}
}

to

Code:
if ($per_add) {
if ($rec{'Position'} eq 'Pitcher') {
print qq|<a href="$db_script_url?db=pitching&uid=$db_uid&PlayerID=$rec{'PlayerID'}&add_form=1">
Add pitching statistics for this player</a>
|;
}
else {
print qq|<a href="$db_script_url?db=htting&uid=$db_uid&PlayerID=$rec{'PlayerID'}&add_form=1">
Add hitting statistics for this player</a>
|;
}
}

To sort the "List All" command, just add

Code:
&sb=the number of the last name field

to the "List All" link in sub html_footer.

You will just be searching for players, right? Is there any chance that you will want to get the statistics for everyone in a given year? (Doesn't sound like something you would need to do, but I want to make sure.)


------------------
JPD








[This message has been edited by JPDeni (edited May 01, 2000).]
Quote Reply
Re: Some Odd Questions :) In reply to
Carol,

Wow! It all works great! Thanks so much! There are a few little changes I've also been wondering about...one of them might be a little too much of an undertaking...this thread is getting huge though, I'll start a new one...

Chris
Quote Reply
Re: Some Odd Questions :) In reply to
Good idea.

If anyone is following along, this thread is continued at http://www.gossamer-threads.com/...m12/HTML/002839.html .


------------------
JPD






> >