Gossamer Forum
Home : Products : DBMan : Customization :

Relational mod - cant display user's records...

Quote Reply
Relational mod - cant display user's records...
Hello!

I'm having some real problems with displaying user's records. I have similar problems as described here: http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/002683.html .

$status2 returns "no matches found" everytime i try to display records that belong to a particlar user.
Code:
foreach $col (@db_cols) {
print "$col<BR>";}

This code prints a list of my edit.cfg colums columns - ok.

My codes:

Code:
sub switch_to_edit {
#-------------------------------------------
$cols = 'rID,Date,UserID,Program Name,Review Title,Review';
@db_cols = split (/,/, $cols);
$db_file_name = $db_script_path . "/databases/reviewz.db";
$db_sort{'DateAdded'} = 'Date';
}

sub switch_to_user {
#-------------------------------------------
$cols = 'UserID,Name,E-mail,Display E-mail,ICQ,Website URL,Empty';
@db_cols = split (/,/, $cols);
$db_file_name = $db_script_path . "/databases/users.db";
$db_key_pos = 0;
}


Here is what i have in sub html_record:
Code:
&switch_to_edit;
foreach $col (@db_cols) { print "$col<BR>";} # prints edit.cgi's columns
undef %in;
$rec{'UserID'} =~ s/<?.B>//g;

$in{'UserID'} = $rec{'UserID'} ;
$in{'sb'} = 1;
$in{'so'} = 'descend';
$in{'mh'} = 100;

my ($status2,@hits2) = &query("view");
print "$status2"; #prints status of search
if ($status2 eq "ok") {
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);
print "<table>";

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

Database definitions for user.cfg
Code:
%db_def = (
UserID=> [0,'alpha',-1,8,1,'',''],
Name => [1,'alpha',40,45,1,'',''],
'E-mail'=> [2,'alpha',40,80,, '', '.+@.+\..+'],
'Display E-mail' => [3,'alpha',0,3, 1,'No',''],
ICQ => [4,'numer',10,10,0,'','\d{5}'],
'Website URL' => [5,'alpha',40,300, 0,'','^http|ftp'],
Empty=> [6,'alpha',1,1,0,'','']);

Here are my db definitions for edit.cfg:
Code:
rID => [0,'alpha', -1,8,1,'',''],
Date => [1,'date',-1,15,1,&get_date,''],
UserID => [2,'alpha',-1,15,1,'',''],
'Program Name' => [3,'alpha',0,50,1, '---',''],
'Review Title' => [4,'alpha',0,50,1,'',''],
Review => [5,'alpha',0,500, 0,'','']

and heres what my databases look like:
Code:
user.db

User2|User2 Name|user2@nowhere.com|Yes|1234567|http://none.com|


edit.db
13|27-Apr-2000|User2|SomeProgramName|What i think of it|User comments go here.

[This message has been edited by db (edited April 27, 2000).]
Quote Reply
Re: Relational mod - cant display user's records... In reply to
Hello!

Yep i logged in into edit database, did a search and it returned 9 matches (thats exactly how many records belong to User2).

After adding this:
Code:
foreach $key (sort keys %in) {
print "$key: $in{$key}<BR>";}
I get these lines:

UserID: User2
mh: 100
sb: 1
so: descend

Quote Reply
Re: Relational mod - cant display user's records... In reply to
If you do a search from the form in the "edit" database for

UserID=User2

you get records returned?

If so, the next thing to do is print out the whole %in hash.

(Debugging is such a pain! Smile )

After

$in{'mh'} = 100;

add

Code:
foreach $key (sort keys %in) {
print "$key: $in{$key}<BR>";
}

Let me know what you get.


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






Quote Reply
Re: Relational mod - cant display user's records... In reply to
The first thing I see is

Code:
sub switch_to_edit {
#-------------------------------------------
$cols = 'rID,Date,UserID,Program Name,Review Title,Review';
@db_cols = split (/,/, $cols);
$db_file_name = $db_script_path . "/databases/reviewz.db";
$db_sort{'DateAdded'} = 'Date';
}

It should be

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

You can take out

Code:
foreach $col (@db_cols) { print "$col<BR>";} # prints edit.cgi's columns

That's just for debugging.

Now for another debugging line.

After

$in{'UserID'}

add

print "$in{'UserID'}<BR>";


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








[This message has been edited by JPDeni (edited April 28, 2000).]
Quote Reply
Re: Relational mod - cant display user's records... In reply to
Hello there!

Code:
print "$in{'UserID'}<BR>";
This line outputs the currect user(User2).

As you have noticed, i have the following line:
Code:
print "$status2";
And everytime it returns "no matching records". I've double/triple checked my databases for the right order of fields and i've checked that i have records created by User2 (i've even checked the case, unwanted spaces, etc).
Quote Reply
Re: Relational mod - cant display user's records... In reply to
This is another thing that doesn't make any sense to me. (There have been several like that lately.)

Do you by any chance have

$auth_view_own = 1;

for either of the databases?



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






Quote Reply
Re: Relational mod - cant display user's records... In reply to
Hello again!

I was going mention in my last post that i have $auth_view_own=1;
in both databases, but i tried setting it to 0(zero) in the edit.cfg and it still didnt display anything (the debug line $status2 returns "no matching records").

So, yes i do have
$auth_view_own = 1;
in both .cfg's.


------------------------------------------

I have installed the following mods(if that helps you):

Autogenerate Enhancements
Automatic View/Modify Search
Bug Fixes
Misc Changes

[This message has been edited by db (edited April 28, 2000).]
Quote Reply
Re: Relational mod - cant display user's records... In reply to
I just noticed something else, but I don't know if it would cause your problem.

In sub switch_to_edit, you have

$cols = 'rID,Date,UserID,Program Name,Review Title,Review';

and

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

There's no 'DateAdded' field. I think you want to change that to

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

Again, I don't think it would make a difference.

Try commenting out the lines

$in{'sb'} = 1;
$in{'so'} = 'descend';
$in{'mh'} = 100;

and see if you get anything.


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






Quote Reply
Re: Relational mod - cant display user's records... In reply to
I did as you told me to - nope ... Frown

[This message has been edited by db (edited April 28, 2000).]
Quote Reply
Re: Relational mod - cant display user's records... In reply to
Hey there!

I dont get it...
I've been experimenting here for the last few hours...
And what do ya know... In user.cfg, I set $auth_view_own back to 0(zero) and the user's records are now being shown!!! I swear, i've done that before and it didnt work...

So now i have another problem. If i set $auth_view_own to 0, the other user's infos can be view by all and i dont want this happening... is there a solution?
Quote Reply
Re: Relational mod - cant display user's records... In reply to
JPDeni!!!

I cannot thank you enough!!!
You are a savior!!!

Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile
Quote Reply
Re: Relational mod - cant display user's records... In reply to
Well, I'm persistent. Smile

Glad I could *finally* figure it out.


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






Quote Reply
Re: Relational mod - cant display user's records... In reply to
Okay. Now we've got it! Smile

In each of your "switch" subs, add

Code:
$auth_user_field = 0;

or whatever the $auth_user_field is. Make it just like the line in your .cfg file.

You can now set it up with

$auth_view_own=1;

and everything will be fine. Smile

(You can also take out all those debugging lines.)


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