Gossamer Forum
Home : Products : DBMan : Customization :

Relational Database

Quote Reply
Relational Database
 
I have set up two databases, one with the users personal information in it and one default database. They are linked by one key field, which I am sure that I have set correctly to match the auth_user field.

However, when I query the default database, only the first item in my search has the information from the user database appended to it. All other database entires have blank spaces where the rec2{'Fieldnames'} should be.


Code:

&switch_to_comp_db;
$in{'Userid'} = $rec{'Userid'};
my($status, @rec2) = &query("view");


if ($status eq "ok" && $db_total_hits == 1) {
%rec2 = &array_to_hash(0, @rec2);
&switch_to_default_db;

Does anyone have any thoughts on what could stopping the users information from appearing in all but the first record
Quote Reply
Re: Relational Database In reply to
This is really important to me, if anyone has a solution, or even an idea about what could be causing this, I would really like to hear it.

Thanks
Quote Reply
Re: Relational Database In reply to
Sorry I don't have an answer for you but I am looking to implement something similar...can you point me to the source of the relational mods (any pointers would be paid with karmic good will Wink )

Thanks
Quote Reply
Re: Relational Database In reply to
The instructions on how to make the regular dbman into the relational dbman are at:
http://www.jpdeni.com/dbman/Mods/relational.txt

good luck with it, and let me know how it goes.
Quote Reply
Re: Relational Database In reply to
Try removing the
&& $db_total_hits == 1
from the if statement.
see what happens.

or change to
&& $db_total_hits >= 1

(greater than or equal to 1)


[This message has been edited by Dave T (edited February 10, 2000).]
Quote Reply
Re: Relational Database In reply to
I am afraid that did not do it. Here is my whole chunk of code from the html_record_long

I have made some changes since my last post, so I am including everything that is relevant to the problem.

Code:
&switch_to_comp_db;
$in{'UserID'} = $rec{'UserID'};
my($status2, @hits2) = &query("view");

if ($status2 eq "ok") {
%rec2 = &array_to_hash($_, @hits2);

print qq~

<hr width="60%" color="black" noshade size="1"><br>
<div align="center">
<table border="1" bgcolor="#FFFFF0" cellspacing="1" bordercolordark="#000000" bordercolorlight="#000000" width="343">
<tr>
<td width="333">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<p align="center"><b><u><$font>Business Card</u></b></td>
</tr>
<tr>
<td width="100%">

<p align="left"><font color="#000080"><b>$rec2{'Company'}</b></font><br>

$rec2{'Address1'}<br>
$rec2{'City'}, $rec2{'State'} $rec2{'Zip'}</font><br>
<font color="#FFFFF0">.</font></td>
</tr>
<tr>
<td width="100%" height="62"><$font><b>Tele:</b>$rec2{'Phone'}
<b>Fax:</b> $rec2{'Fax'}<br>
<b>E-Mail:</b> <a href="mailto:$rec2{'Email'}">$rec2{'Email'}</a><br>
<b>Web:</b> <a href="$rec2{'URL'}">$rec2{'URL'}</a></font></p>
</tr>
</table>
</td>
</tr>
</table>
</div>

~;
}
##### prints an error if unable to get company info ########
else{
print qq~
<table cellpadding="4" width="100%" border="0">
<tr><td>
<font size="+1">Error:</font>Unable to retrieve contact information. Please take the time to <a href="mailto:$admin_email">E-mail</a> the web site manager so this can be corrected.<br>Thank You.
</td></tr>
</table>~;

&switch_to_default_db;
}

print qq~
</td></tr>
</table>~;
Quote Reply
Re: Relational Database In reply to
The calling of the switch routines should go in your sub html_record and/or sub html_record_long NOT in your sub view_sucess routine.

SNIPPET of codes from JPDeni's Tutorial...

Code:
So that my entire subroutine would be

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.
&switch_to_user;
%rec2 = &get_record($rec{'UserID'};
&switch_to_item;
($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_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>Item:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Item'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Classification:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Classification'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Price:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Price'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Description:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'Description'}</Font></TD></TR>
<TR><TD>Offered by:</TD>
<TD><a href="mailto:$rec2{'UserEmail'}">$rec2{'UserFirstName'} $rec{'UserLastName'}</a></TD></TR>
<TR><TD>From:</TD>
<TD>$rec2{'UserCity'} $rec2{'UserState'} $rec2{'UserCountry'}</TD></TR>
</TABLE>
|;
}

You will probably want to have links in the footer to go back and forth between
the databases. You can copy the links that are in sub html_footer, except that
you will need to change $db_script_link_url to $db_script_url?db=database name&uid=$db_uid

Notice...that the codes are in the sub html_record routine.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------








Quote Reply
Re: Relational Database In reply to
Eliot,
The code that I posted above WAS from
sub html_record_long. I just did not include the whole sub because it is quite lengthy.

Below is the code that I am using to switch between databases.
Code:
#
#
# ----------------------
# DBMan
# ----------------------
# Database Administrator
#
# File: format.pl
# Description: This is the file that that sets up a global setting for multiple databases. It
# also contains sub-routines to switch between database files.
#


##########################################################
## HTML Globals ##
##########################################################
# Put any globals you like in here for your html pages.
$html_title = 'AntiqueExchange.net';

# Add your email address. Be sure to leave the \ before the @
$admin_email = "maps1\@erols.com";

# Set your font preferences below
#
$face = 'font face=Verdana, Arial, Helvetica'; # font face for pages
$font = "$face size=2"; # size of normal text
$font_color = "$font color=#003399"; # an alternate color font for html_record
$font_title = "$face size=4"; # size of title text
$error_color = 'font color=red'; # color of error messages
$font_error = "$face size=4 color=red"; # large font for error messages


###############################################################################################
##########################---SUB SWITCH_TO_COMP_DB------#######################################
sub switch_to_user_db{

@db_cols = qw(Userid Company Address1 Address2 City State Zip Phone Fax Email URL);
$db_file_name = $db_script_path . "/user.db";
$db_key_pos = 0;

}

##############################################################################################
#############################----SUB SWITCH_TO_DEFAULT_DB------###############################
sub switch_to_default_db{

@db_cols = qw(Userid ID Category Title Price Quantity Date Desc1 Desc2 Desc3);
$db_file_name = $db_script_path . "/default.db";

}
1


You can find my http://207.96.11.60/jpdeni/html.txt
http://207.96.11.60/jpdeni/default.txt




[This message has been edited by dataKing (edited February 11, 2000).]
Quote Reply
Re: Relational Database In reply to
Well, those status codes and query_view codes do NOT need to be there. Copy and use the exact codes that JPDeni wrote.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------








Quote Reply
Re: Relational Database In reply to
Eliot,
Those status codes come straight out of jp's mod!

But anyway, I get the exact same result if I erase my sub html_record_long mod, and put her's in. Maybe I don't have the cfg files configured correctly, I will post the *.cfg files at

http://207.96.11.60/jpdeni/default.txt
http://207.96.11.60/jpdeni/user.txt
Quote Reply
Re: Relational Database In reply to
If you look at the mod...She has not included these codes in the sub html_record routine. Did you even look at the codes that I POSTED DIRECTLY FROM JPDENI'S MOD!

Anyway...since it seems that you haven't and are unwilling to take my advice...best of luck!

May be someone else can help you.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: Relational Database In reply to
Eliot,
Why are you getting so bent out of shape by what I wrote??? All I am doing is trying to work out a bug, and you are taking it upon yourself to yell at me!?!

And as for advice, you have yet to give me any! All you have told me is to
quote:
Code:
Well, those status codes and query_view codes do NOT need to be there. Copy and use the exact codes that JPDeni wrote.

Which, in my next post I said that I tried using the exact code from her mod and it did not work.

I don't want to be rude, I don't want to debate, I just want to learn about perl and get this mod working. If you can help me, without flaming me in the process, then I would appreciate it.

Again, my problem is:
I can not get the relational mod working. The fields that I am using for the second database do not contain the information from the second database. I have tried using the exact code from jp's mod and I still get an error.
I think the error may be in the my cfg file, can someone please take a look at it and let me know if you see a set up mistake. Thanks.

I forgot to mention that you can find my scipt at:

http://207.96.11.60/jpdeni/html.txt
'' default.txt
'' user.txt




[This message has been edited by dataKing (edited February 14, 2000).]
Quote Reply
Re: Relational Database In reply to
Default cfg OK... user cfg wrong... $db_key should be Userid, and don't track (assuming that it is a name and not a sequential number)...

You might want to look at JPDeni's example a little closer... she discuses the key field in depth.

------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)


[This message has been edited by oldmoney (edited February 15, 2000).]
Quote Reply
Re: Relational Database In reply to
testing