Gossamer Forum
Home : Products : DBMan : Customization :

DB Out

Quote Reply
DB Out
Kellner suggest I put this in the forum. I am trying to make a roster for a gaming site. I found a MOD that puts the title at the top & the contents below in one table:

http://webmagic.hypermart.net/dbman/db/text/dbout.txt

This is almost what I need, but I would also like the individual cells columns/rows to have borders (to separate them). I haven’t found any other mods that list the output horizontally in this way. (i can't make it line up right in this forum but basically it looks like this and works):

NAME RANK EMAIL BARONY JOINED
Fandrall Duke fandrall@home.com All 01-Nov-1995
Bard Count dabard@quik.net All 07-Feb-1997
Raeana Baron dianarae@bellsouth.net Nest 25-Jul-1999
Justice Baron darkjustice@aol.com Rivervale 02-Feb-1999
Pulgrey Knight pulgrey@home.com Nest 01-Sep-2000
Sarm Elite sarmarn@igt.net Nest 03-Aug-2000
Bisl Court bisl@home.com Rivervale 21-Nov-2000
Catsreyn Squire catsreyn@home.com Rivervale 19-Jan-2001
Teala Squire teala@home.com Nest 03-Mar-2001

However, with this mod when you do a “list all” the email links no longer work. I searched & searched and cannot figure out what part is missing to have the links print on this page with this mod.

Also, when I first made this database I had it in the original Dbman format:

NAME: Fandrall
RANK: Duke
EMAIL: fandrall@home.com
BARONY: ALL
JOINED: 01-Nov-1995

When it was in this format Kellner I found notes in this forum to have the results display in rank order by putting a number in front of the rank: 1Duke,2Count,3Baron,4Knight etc. Then Kellner was so kind as to give me a code to delete that first number when the list printed & it worked with the original layout of the above table:

if ($rec{'Rank'} =~ /^(\d)(\w+)$/) { $rec{'Rank'} = $2;}) {

However, now in the MOD shown at the top where the contents print in one table Kellners code to drop the number no longer works and the number stays on when it prints.

I have tried every which way to put this all together and nothing works.

Here is the MOD:

In .cfg set autogenerate to 1



In html.pl

1) Find this code, in any of the subroutines that output results, such as html_view_success, and

# Go through each hit and convert the array to hash and send to
# html_record for printing.

for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits));
}

2) delete it, and copy the following in it's place:

# Go through each hit and convert the array to hash and send to
# html_record for printing.
print "<table>";
print "<tr><td>",join('</td><td>',@db_cols),"</td></tr>";
for (0 .. $numhits - 1) {
&html_record_row (&array_to_hash($_, @hits));
}
print "</table>";

3) Add this to your html.pl file

#### This subroutine calls build_html_row, for printing in rows
## Insert this into html.pl

sub html_record_row {
my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record_row(%rec) and return);
}

4) Add this to your db.cgi file

# ADD this to db.cgi
# Builds a record based on the config information.
sub build_html_record_row {

my (%rec) = @_;
my ($output, $field);
$output = "<tr>";
foreach $field (@db_cols) {
next if ($db_form_len{$field} == -1);
$output .= qq~
<td align=left><$font>$rec{$field}</font></td>
~;
}
$output .= "</tr>\n";
return $output;
}

As I said this MOD is great & works just as I need it with the header at the top & content below, but the problems remain:

1. This mod puts everything in 1 table & I need the individual rows to have borders to separate them.
2. This mod does not print the email links when they are displayed in “list all”.
3. The code Kellner helped me with to remove the number in front of the rank name when printed in this MOD.

Those are the only 3 things I cannot get working with this mod. If anyone has any clue as to what I might do to get these things working I would appreciate it greatly.
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
I spent the day (and actually the past week in total) reading everything I could find about perl on the 3 issues I have. I still cannot figure out the answers.

If anyone has a clue where I might start I'll make chocolate chip cookies for you (homemade). Wink
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
Try adding the part in bold...

Code:
# Builds a record based on the config information.
sub build_html_record_row {

my (%rec) = @_;
my ($output, $field);
$output = "<table border=1><tr>";
foreach $field (@db_cols) {
next if ($db_form_len{$field} == -1);
$output .= qq~
<td align=left><$font>$rec{$field}</font></td>
~;
}
$output .= "</tr></table>\n";
return $output;
}

This may, or may not, work but hopefully it'll give you the idea... (try randomly sticking in table tags and see what happens) Wink

Make only one change at a time, have a back-up and if it doesn't work change it back before changing the next thing.

Good Luck!
Quote Reply
Re: [dianarae] DB Out In reply to
Gracious! I did part of it.......whoooooo whoooooooo Laugh

It's almost EXACTLY as I need now, but for 1 small error......

take a look (this is a default "list all":

http://www.aallsafe.com/NOR/roster/test/test.cgi?db=test&uid=default&view_records=1&ID=*&sb=3

As you can see the layout is exactly as I wanted it to be and the code kellner gives me even made the ranks sort properly (in the correct rank order) AND and the number is removed for the front of each rank when the list is printed!! Cool

NOW the ONLY problem (for the moment) that I can see is that when you go to search and choose an individual rank it once again puts the number in front of the rank. For instance if you didn't choose "list all" and went to Search instead and let's say you did a search on: "Rank: 4CC". As you can see the # is now back in front of the print out.

Kellner gave me the code:

if ($rec{'Rank'} =~ /^(\d)(\w+)$/) { $rec{'Rank'} = $2;} {

to put above the Rank in the sub html_record and that worked terrific. But this code didnt work when I tried it above Rank in the sub html_record form.

Help me help me! How do I drop this number in the search printout the same way it is drops when you list all? Crazy
Diana Rae
Quote Reply
Re: [Watts] DB Out In reply to
Wow, Watts you must have been posting at the same time I was. I will try what you put there in lieu of what I did perhaps that will solve my newest problem.

But, if you wouldn't mind taking a look at the link I just posted so you can see that it is what I wanted exept for that 1 little part of when you hit the drop down list it shows the # in front of rank on the search (but doesnt in list all). In fact, in the search if you type in a name (let's say Lilly) or type in an email in search (lilly@lilly.com) the # doesnt show in the search results for those - only when you use the drop down box. Can you understand why?

PS. private me your address for your cookies Wink
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
Well, i have worked & worked & worked with that code you gave me and this is the best I could do:

http://www.aallsafe.com/NOR/roster/roster1/test/test.cgi?db=test&uid=default&view_records=1&ID=*&sb=3

and even with that layout (which i have everything to format it properly with tags & that is the best I have been able to get). And with this the # before the rank still shows. Unimpressed

Now, look at this the other one that I had posted above:

http://www.aallsafe.com/NOR/roster/test/test.cgi?db=test&uid=default&view_records=1&ID=*&sb=3

Everything on this one works, except as I said, it shows the number before the "rank" only when you do a search on a rank. Is there a way to fix that? Pirate
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
Yeah, you're second option looks much better. The sample I gave won't generate the table tags properly and would cause problems in some browsers. Stick with the one you did...

Later on today/this weekend I'll check it out to see if I can give you any advice, but I'll admit I'm not familiar with the mod you're working with so I may not be able to help. However, I'll try.
Quote Reply
Re: [dianarae] DB Out In reply to
Quote:
Everything on this one works, except as I said, it shows the number before the "rank" only when you do a search on a rank. Is there a way to fix that?




I noticed that it is still bolding search results, try changing the setting in the config file. look for the line

# Bold search results (1 = Yes, 0 = No).
$db_bold = 0;
Quote Reply
Re: [Watts] DB Out In reply to
OK, thanks Watts. I'll continue using the second one. I left the sub html_record_form the same layout of the standard dbman (name email rank in the left column - outputs in the right column).

As I said, the code Kellner gave me for the sub html_record works like a champ - to drop the # in front of the ranks when you do a "list all, search by name and search by email. The print drops the 1 in front. However, when you hit the drop down list for rank (on search) the printout does not drop the number. I am not sure how to fix that.

I know that people will want to search by ranks as we have a couple hundred members & I really don't want that number to show in front of the rank name when the do a search. Unsure

Just so you can see here they are:

sub html_record_form {
# --------------------------------------------------------
# The form fields that will be displayed each time a record is
# edited (including searching). You don't want to put the
# <FORM> and </FORM tags, merely the <INPUT> tags for each field.
# The values to be displayed are in %rec and should be incorporated
# into your form. You can use &build_select_field, &build_checkbox_field
# and &build_radio_field to generate the respective input boxes. Text and
# Textarea inputs can be inserted as is. If you turn on form auto
# generation, the program will build the forms for you (all though they may
# not be as nice). See the README for more info.

my (%rec) = @_;
($db_auto_generate and print &build_html_record_form(%rec) and return);

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

print qq|
<TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1
BGCOLOR="#FFFFCC">
|;
if ($per_admin) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>ID:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475">&nbsp;<INPUT TYPE="TEXT" NAME="ID" SIZE="20"
VALUE="$rec{'ID'}" MAXLENGTH="255"></TD></TR>
|;
}
else {
print qq|
<input type="hidden" NAME="ID" VALUE="$rec{'ID'}">
|;
}
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Name:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475">&nbsp;<INPUT TYPE="TEXT" NAME="Name" SIZE="20"
VALUE="$rec{'Name'}" MAXLENGTH="255"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Email:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475">&nbsp;<INPUT TYPE="TEXT" NAME="Email" SIZE="20"
VALUE="$rec{'Email'}" MAXLENGTH="255"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Rank:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475">&nbsp;|; print &build_select_field("Rank",$rec{'Rank'}); print
qq|</TD></TR>
</TABLE>
|;
}

sub html_record {
# --------------------------------------------------------
# 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.
($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';

$url{'Email'} = $rec{'Email'};
$url{'Email'} =~ s/<\/?B>//g;

print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=1
BGCOLOR="#FFFFCC">|;
if ($per_admin) {
print qq|
<tr>
<td width="10%">
<p align="center">&nbsp;<$font>$rec{'ID'}</Font></td>
|;
}
print qq|
<td width="30%">
<p align="center">&nbsp;<$font>$rec{'Name'}</Font></td>
<td width="30%">
<p align="center">&nbsp;<$font><a href="mailto:$url{'Email'}">$rec{'Email'}</a>|;
if ($rec{'Rank'} =~ /^(\d)(\w+)$/) { $rec{'Rank'} = $2;} {
print qq|
<td width="30%">
<p align="center">&nbsp;<$font>$rec{'Rank'}</Font></td>
</tr>
|;
}
print qq|
</table>
|;
}

I really appreciate your help. Smile
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
I also am using rank in my database, But what i do is to store numbers in the actual .db file itself and when it is printed the numbers are converted to the actual ranks itself and it works just fine.
Julian
Quote Reply
Re: [vampy] DB Out In reply to
Could you please explain what you mean?
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
Okay, in my db.cfg, I define my field as Rank. I add the following to the db.cfg:


%Rank = (8 => 'Trainee Instructor',7 => 'Lieutenant',6 => 'Lieutenant Commander',5 => 'Commander',4 => 'Captain',3 => 'Commodore',2 => 'Fleet Admiral',1 => 'Admiral',h => 'Senior Fellow',g => 'Doctor',f => 'Assistant Professor',e => 'Associate Professor',d => 'Professor',c => 'Dean',b => 'Vice-Chancellor',a =>'Chancellor'
);

Note that the above should NOT be added to the %db_select_fields.

Then I add this new sub to html.pl

sub build_fancy_select_field {
#---------------------------------------------------------
my $field = $_[0];
my $compare = $_[1];
my %Selector = (
'Rank' => [
['---','Select one'],
['1','Admiral'],
['2','Fleet Admiral'],
['3','Commodore'],
['4','Captain'],
['5','Commander'],
['6','Lieutenant Commander'],
['7','Lieutenant'],
['8','Trainee Instructor'],
['a','Chancellor'],
['b','Vice Chancellor'],
['c','Dean'],
['d','Professor'],
['e','Associate Professor'],
['f','Assistant Professor'],
['g','Doctor'],
['h','Senior Fellow'],
],
);

$output = qq|<SELECT NAME="$field">\n|;
$i = 0;
while ( $Selector{$field}[$i][0] ) {
($Selector{$field}[$i][0] eq $compare) ?
($output .= qq|<OPTION VALUE="$Selector{$field}[$i][0]" SELECTED>$Selector{$field}[$i][1]\n|) :
($output .= qq|<OPTION VALUE="$Selector{$field}[$i][0]">$Selector{$field}[$i][1]\n|);
++$i;
}
if ($i) { $output .= "</SELECT>"; }
else { $output = "Incorrect field definition"; }
return $output;
}

Then I change sub html_record_form where the Rank field is to:

print qq|
<TD ALIGN="Left" VALIGN="Middle" WIDTH="10%"><$font_color>Rank:</FONT></TD>
<TD VALIGN="Middle" WIDTH="40%">&nbsp;|; print &build_fancy_select_field("Rank",$rec{'Rank'}); print qq|</TD></TR>|;
Also, in sub html_record change the field of the Rank to:

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Rank:</FONT></TD>
<TD WIDTH="80%">&nbsp;<$font>$Rank{$rec{'Rank'}}</Font></TD></TR>

Note the words in red. That is what allows the database to change the numbers as defined in sub build_fancy_select_field and those define by %Rank in db.cfg back to the names of the rank.
Julian
Quote Reply
Re: [vampy] DB Out In reply to
Diana, replace build_select_field in your db.cgi with the following code. I'm assuming here that the rank field is called "Rank".



sub build_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition. Parameters are the column to build
# and a default value (optional).

my ($column, $value) = @_;
my (@fields, $ouptut);

@fields = split (/\,/, $db_select_fields{$column});
if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
}
else {
if ($column eq "Rank") {
$output = qq|<SELECT NAME="$column"><OPTION>---</option>|;
foreach $field (@fields) {
my %nonumfield;
if ($field =~ /(\d)(\w+)$/) {$nonumfield{$field} = $2;}
$field eq $value ?
($output .= qq|<option selected value="$field">$nonumfield{$field}</option>| ) :
($output .= qq|<option value="$field">$nonumfield{$field}</option|);
}
$output .= "</SELECT>";
}
else {
$output = qq|<SELECT NAME="$column"><OPTION>---|;
foreach $field (@fields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";}
}
return $output;
}

What this does: the rank *with* the number is passed to the database for searching, but the visitors get to see the rank without the number.
kellner
Quote Reply
Re: [kellner] DB Out In reply to
Vampy,

I'm still not exactly sure what you mean. I have other fields in my .cfg file as well, Name, email, rank etc. Where exactly would this field definition go if not in the select area?

Kellner, yes the field is called "Rank". And yes, this is exactly what I need it to do. I tried this code you showed here and it did drop the number in the drop down list, but it also stopped it from "dropping down" and rank all the names together. Hit the drop down box & take a look:

http://www.aallsafe.com/NOR/roster/test/test.cgi?db=test&uid=default&view_search=1

I put the code exactly as you showed. Did I miss something?
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
Can anyone see in Kellner's code above that might make the select field run together? Crazy The code did drop the #, but as you can see the fields are all in one line run together. Unsure
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
Try changing these two lines:

From:

($output .= qq|<option selected value="$field">$nonumfield{$field}</option>| ) :
($output .= qq|<option value="$field">$nonumfield{$field}</option|);

to:

($output .= qq|<option selected value="$field">$nonumfield{$field}</option>|; ) :
($output .= qq|<option value="$field">$nonumfield{$field}</option>|;);

see if that helps

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] DB Out In reply to
Thank you, Lois & Kellner.

I got an internal error when I tried your code, Lois so I played around with it & took out one of the semicolins & then it worked. Thanks so much! Sly

This is what worked:

($output .= qq|<option selected value="$field">$nonumfield{$field}</option>| ) :
($output .= qq|<option value="$field">$nonumfield{$field}</option>|);
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
1 step forward.....2000 steps back.

Like I said, the code worked great. But, this was a test. In the actual database I have about 20 ranks.

When I tried to add them everything worked great until I got to rank 10 on up.

When the drop down list is displayed in the real database it now shows:

QuestSpecialist

ChampionElite

ChampionHonor

ChampionCourt

Champion

KnightProtector

KnightElite

KnightHonor

KnightCourt

0Knight

1SquireElite

2Squire

The numbers are added again after I hit 9. Is 9 the max I can use? Unsure
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
To get the code working with numbers from 10 upwards, change the routine I gave you to this.

if ($rec{'Rank'} =~ /(\d+)(w+)$/) { $rec{'Rank'} = $2;}

The important part is the + sign after the letter "d".
kellner
Quote Reply
Re: [kellner] DB Out In reply to
Whooo hooo thanks Kellner! Actually I also had to add the + in the cgi, not just the html.pl to make it work. But, it WORKS! Sly

Thanks so much!!
Diana Rae
Quote Reply
Re: [dianarae] DB Out In reply to
Sorry; yes - I forgot to add that you have to change the code wherever you use it ... glad it works now.
kellner