Gossamer Forum
Home : Products : DBMan : Installation :

How to show "many" items of "one" user?

Quote Reply
How to show "many" items of "one" user?
I have a little problem getting the the relational mod from JPDeni working.

Thanks to the great tutorial and documentation of JPDeni, I managed to get set it up for the biggest part. The only problem I have now, and I am not skilled enough to find a solution by myself, is to display the many "items" of one "user". Everything else works, also displaying the "item" with the users info.

The error:

CGI ERROR
==========================================
Error Message : fatal error: Undefined sort subroutine "main::_ascend" called at db.cgi line 471.

Script Location : db.cgi
Perl Version : 5.00502
Setup File : user.cfg
User ID : jan
Session ID : jan.958731502736

Form Variables
-------------------------------------------
UserID : agabird
UserID-lt : B>agabird
mh : 100
sb : 4


From the user_html.pl the sub html_record looks like this:

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{'UserEmail'} = $rec{'UserEmail'};
$url{'UserEmail'} =~ s/<\/?B>//g;
$url{'UserUrl'} = $rec{'UserUrl'};
$url{'UserUrl'} =~ s/<\/?B>//g;

print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">|;
if ($per_admin) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserID:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserID'}</Font></TD></TR>
|;
}
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserName:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserName'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCountry:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCountry'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserState:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserState'}</Font></TD></TR>|;
if ($rec{'UserCity'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCity:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCity'}</Font></TD></TR>
|;
}
print qq||;
if ($rec{'UserPhone'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserPhone:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserPhone'}</Font></TD></TR>
|;
}
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserEmail:</FONT></TD>
<TD WIDTH="80%"> <$font><a href="mailto:$url{'UserEmail'}">$rec{'UserEmail'}</a>|;
if ($rec{'UserUrl'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserUrl:</FONT></TD>
<TD WIDTH="80%"> <$font><a href="$url{'UserUrl'}">$rec{'UserUrl'}</a>
|;
}
print qq|
</TABLE>
|;


&switch_to_item;
undef %in;
$in{'UserID'} = $rec{'UserID'};
$in{'sb'} = 4;
$in{'mh'} = 100;

my ($status2,@hits2) = &query("view");

if ($status2 eq "ok") {
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);
print qq|
<TABLE>|;

for (0 .. $numhits2 - 1) {
%rec2 = &array_to_hash($_, @hits2);
print qq|
<tr><td>
<a href="$db_script_url?db=item&uid=$db_uid&ItemID=$rec2{'ItemID'}&view_records=1">$rec2{'Type'}
</a><BR>
</td></tr>|;
}
print qq|
</TABLE>|;
}
&switch_to_user;
}


The changes I made in db.cgi was only adding the following :

##########################################################

sub switch_to_item {
#-----------------------------------------------------
$cols = 'UserID,ItemID,Rubr,Type,DateAdded,Description';
@db_cols = split /,/,$cols;
$db_file_name = $db_script_path . "/item.db";
}

sub switch_to_user {
#-----------------------------------------------------
$cols = 'UserID,UserName,UserCountry,UserState,UserCity,UserPhone,UserEmail,UserUrl';
@db_cols = split /,/,$cols;
$db_file_name = $db_script_path . "/user.db";
$db_key_pos = 0;
}
##########################################################


Please could anyone tell me what I'm doing wrong??

Quote Reply
Re: How to show "many" items of "one" user? In reply to
The problem is that you are sorting the items. If you don't use $in{'sb'}= when you search for the items, you should be just fine.

If you want to sort by that field, you'll need to add a line to your "switch_to_item" subroutine for that database, like I did in the relational mod with the DateAdded field. Since you are also sorting by the date, you can use the line I have in the mod.

$db_sort{'DateAdded'} = 'date';

I need to make that clearer in the mod.




JPD
Quote Reply
Re: How to show "many" items of "one" user? In reply to
Yes!!

It works. Thank you very much, not only for your answer but for all the great work you do for making dbman for what it is.

BTW there are more things in the relational mod documentation that may be worth changing. There are several little errors. It costs a beginner some time to figure out how to get errors right.

If you are interested, I can give you a list of the the parts, of which I think, that contains an error.

All above are based on the relational.txt, which I downloaded from your page.

Again,
Thanks
Jan.

Quote Reply
Re: How to show "many" items of "one" user? In reply to
Sure, Jan. I'd like that a lot. Sometimes my ol' brain sorta falls apart when I'm writing things. Smile

Why don't you send me a private message here on the forum. Just click my name and you should get a screen with the option to send me a private message. Then I'll get it all fixed up and we'll be cookin' with gas! Smile


JPD