Gossamer Forum
Home : Products : DBMan : Customization :

Two database keys

Quote Reply
Two database keys
Hi All

Is it possible to have two database keys or one database key and a sperate counter?

Example:

db_key | another_counter | field 1 | field 2

1 | 5 | data | data

2 | 6 | data | data

3 | 7 | data | data

Thanks

Adam
Quote Reply
Re: [achandler] Two database keys In reply to
You could do it, but it would take a lot hunting.

In default.cfg you'd have to create duplicates for:

$db_id_file_name = $db_script_path . "/default.count";
$db_id_file_name2 = $db_script_path . "/another.count";

and

$db_key = 'ID';
$db_key2 = 'another_counter';

Then you'd have to hunt down and duplicate the subs or bits of subs that contain
$db_key and $db_id_file_name

Search in db.cgi and auth.pl and probably html.pl - you'd have to make a distinction between the parts of the script that are simply reading the next available number and updating the counter (which is what you want for the second key) from the parts that are using the ID to identify the record for the database purposes (which is what you don't want for the second key).

What do you need the second key for? Could you use Javascript to add a number (say 100) to the ID number and have it populate a hidden field - it'd be much easier.
Quote Reply
Re: [Watts] Two database keys In reply to
Hi

Sorry for the last thanks and reply.

I need to use the database for a part numbering system. For example:

main counter | partnumber counter | data | date

1 | 345 | data | date

2 | 195 | data | date

I will look into the method you mentioned but I am also interested in the javascript method you talked about. How would this work? would it be possible to use this for the main counter?

Thanks again

Adam
Quote Reply
Re: [achandler] Two database keys In reply to
Assuming you have a field called "ID" and a field called "PartNo" do the following:

Under html_add_form

add this:
------------------------------
<SCRIPT LANGUAGE="JavaScript">
function doCount() {
form.PartNo.value = (form.ID.value + "-" + 100);
}
</SCRIPT>

modify this:
------------------------------
<body bgcolor="#DDDDDD" onLoad="doCount();>
<form action="$db_script_url" method="POST" name="form">


And under html_record_form

add this:
------------------------------
<INPUT TYPE="hidden" NAME="PartNo" VALUE="$rec{'PartNo'}">


If your ID was 300 this will assign a PartNo of 300-100 when you add a record.

You could also use:

form.PartNo.value = (form.ID.value * 100);
for 3000

or
form.PartNo.value = (eval(form.ID.value) + 100);
for 400

Also don't forget to add the hidden input tag to html_record as well. The tag doesn't have to be hidden by the way.

Play around with it and see what you get... I tested it in a static html page and it works, but I have not tested it with dbman.

.
Quote Reply
Re: [Watts] Two database keys In reply to
 Hi Watts

I have been working on the two key database (very slowly) and I have managed to get the second counter value into an input box. How ever when testing it, it apears that it does not valadate the field. Therefore one could get to second keys the same. I have played with added it to the valadite sub but with no joy. Any ideas?

Thanks again

AC

Last edited by:

achandler: Feb 11, 2004, 3:33 AM
Quote Reply
Re: [achandler] Two database keys In reply to
If you need it validated then a Perl solution may be necessary (instead of JavaScript).

If I think of something I'll post what I come up with.