Gossamer Forum
Home : Products : DBMan : Customization :

fancier selection from .db file

Quote Reply
fancier selection from .db file
Hello all,

After days and days of reading in the forum and trying for myself (without a result other than creating two server crashes on my ISP due to changes I made myself in the db.cgiBlush ) I come here as a last resort.

1. I am trying to create a dropdown list in the search form. The field is 'user'. I want all 'user's form the .db file listed. (not from the password file since not all users in that file have submitted records). I have tried to make a copy/adjust version of the admin section (pulling users out of password file) in db.cgi but with no results other than described above.

2. I am trying to list those 'user's (from the .db file) in a table with next to their name the amount of records they have submitted in the .db file.

Can this be done and can please someone set me on the right track ?

Greetings,
close_watch

Quote Reply
Re: fancier selection from .db file In reply to
To create a select list whose values come from a field in the database, use

Code:
|;
print &build_select_field_from_db("FieldName",$rec{'FieldName'});
print qq|
Regarding your second question -- this is actually just a little different take on the "List Categories" mod. The index of all of the permutations of "List Categories" is at http://www.jpdeni.com/.../listcategories.html. You probably want

Code:
Category names come from records
For use without the "validate records" mod
If you have trouble figuring it out, don't hesitate to ask.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: fancier selection from .db file In reply to
1. that was quick
2. that was effective
3. seems like I was looking to far
4. THANX !!!!!!



Rock & Roll

Close Watch
Quote Reply
Re: fancier selection from .db file In reply to
You know what they say -- "Timing is everything!" Smile

You're very welcome.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: fancier selection from .db file In reply to
Hi
Got your two suggestions working like a breeze (thanks again).

I am working with two databases and that all works fine too(relationale mod).

Now I've got a list of users ($option)(from your: Category names come from the records) and the amount of records in the db file.

Can I link here in this list somehow the 'one' database with the 'many' so behind the users ($option) i can display rec2(whatever) ?

I've tried many things myself, no luck so far...

Rock & Roll

Close Watch
Quote Reply
Re: fancier selection from .db file In reply to
I'm sure you can, but I'll need a little more explanation -- even an example would be really good!


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: fancier selection from .db file In reply to
Hi JP,

Here it goes;

-----------------------------------------------------------
sub html_author_list {
#======================
my (%rec) = @_; # Load any defaults to put in the VALUE field.

&html_page_top;
&html_print_headers;

$page_title = "Author list";

for ($i = 0; $i <= $#db_cols; $i++) {
#### In the line below, replace 'Category' with the name of your field.
if ($db_cols[$i] eq "Userid" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if ($found) {
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
++$count1{$fields[$fieldnum]};
}
close DB;

&switch_to_author;
%rec2 = &get_record($rec{'Userid'});
&switch_to_default;

print qq|
<P><font color=#FFFFFF>----</font> <$font><b>Authors (+ amount of lyrics)</b></p>
|;
foreach $option (sort keys %count1) {
$encoded = &urlencode($option);


#### In the line below, replace 'Category' with the name of your field.



print "<table align=center width=600><tr><TD width=120 align=left><$lfont>"; # do not remove this! It is necessary to make the records display properly

print qq|
<$lfont></font><a href="$db_script_link_url&Userid=$encoded&Title=&Category=---&Subcat=---&keyword=&mh=10&sb=1&so=ascend&view_records=View+Lyrics&nh=1"><$font>$option</a></font></td>
<td align=left width=80><$font> $count1{$option} <$lfont>lyric(s)</td>
<td align=left width=80><$lfont></font><$lfont>$rec2{'Realfname'}</font></td>
<td align=left width=80><$lfont></font><$lfont>$rec2{'Reallname'}</font></td>
<td align=left width=80><$lfont></font><$lfont>$rec2{'Country'}</font></td>
<td align=left width=80><$lfont></font><$lfont>$rec2{'City'}</font></td>
<td align=left width=80><$lfont></font><$lfont>$rec2{'Country'}</font></td>|;

print "</TR></table>"; # do not remove this! It is necessary to make the records display properly

# |;
}
}

&html_footer;
&html_page_bottom;
}

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

So how do I get $option (from the counting routine) to connect with $Userid in "one" database and returning the values. (rec2)

Tried many things, above code is stripped as far as I could.

Hope this helps, thank you for your time, as always !



Rock & Roll

Close Watch
Quote Reply
Re: fancier selection from .db file In reply to
I think I got it. Smile

Move

Code:

&switch_to_author;
%rec2 = &get_record($rec{'Userid'});
&switch_to_default;
to after

foreach $option (sort keys %count1) {

and change it to

Code:
&switch_to_author;
%rec2 = &get_record($option);
&switch_to_default;
This assumes that the Userid field is the key field for the author database. Right?

BTW, you can make your link a little more concise:

<a href="$db_script_link_url&Userid=$encoded&sb=1&so=ascend&view_records=1"><$font>$option</a></font>

I'm assuming you have the $db_max_hits set to 10 in your .cfg file, so you don't need it in the link. And you don't need empty fields either. The "&nh=1" will automatically be set, so you don't have to worry about that.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: fancier selection from .db file In reply to
Hi JP,

Yes it works !!!
THANX




Rock & Roll

Close Watch