Gossamer Forum
Home : Products : DBMan : Installation :

ID number sorting

Quote Reply
ID number sorting
When I delete a record from my database and then someone add a record, his/her ID # for that record will fill in the place for the first record that was deleted. For example if I have 10 records and I delete record # 5 and #7 then when someone add a new record then he/she will get ID # 5 and it will be put at the end of records but the form will show the ID# for the next record as "6". How can I keep the counter running without resseting it's value when I delete a record so that when I delete record #5 and #7 from above 10 the next record added will be 11, not 5 and then 7, 11
Quote Reply
Re: ID number sorting In reply to
That's what I had before, having problems with the ID# sorting after removing records
Quote Reply
Re: ID number sorting In reply to
Hi Luke,

Set your $db_key_track to 1 and your $db_key to whatever database key field you want to have (in the .cfg). Letting Dbman set the key for you will make the app. work the way you want.

Cheers
-JO
Quote Reply
Re: ID number sorting In reply to
Well I tried that but it doesn't work. I set $db_key = "number that I want" and then there is nothing for ID# on the form instead "the number that I want" because "this number is not equal to "default count" and when I want to see all the records it tells me that the search failed.
Quote Reply
Re: ID number sorting In reply to
Set $db_key to the field that holds the number that you want. If your field name for the key is "ID" set

$db_key = 'ID';

And set $db_key_track to 1.



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





Quote Reply
Re: ID number sorting In reply to
Seems odd, but then odd things happen all the time. Smile

Would you be willing to give us the url for your database so we can see it?


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





Quote Reply
Re: ID number sorting In reply to
OK take a look at: http://cgi-bin.polish.org/cgi-bin/adopt_form/db.cgi?db=adopt&uid=&add_form=1
The ID# says 1 and there are 17 records. Note that the last record does not have any number. The "default.count" seems to be choosing random numbers but never those that are already assigned to the records. It assiagns numbers that were deleted with the record, starting with a null number after deletion.
Quote Reply
Re: ID number sorting In reply to
Okay. I see what's happening. But I still don't know why. Could you post your .cfg file and your .count file in an accessible directory so we can take a look at them? You'll need to rename them with a .txt extension -- defaultcfg.txt and defaultcount.txt -- something like that.

What I find really odd is that your script is doing exactly what I wish I could get my script to do. It would be easier to have consecutive numbers than to have to count the records every time I want to know how many I have.


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

PS. You didn't by any chance take out the &get_defaults part of html_add_form, did you? There should be a line that includes

&html_record_form (&get_defaults);

That could cause the problem you're having.







[This message has been edited by JPDeni (edited March 25, 1999).]
Quote Reply
Re: ID number sorting In reply to
Hey JP,

looks like I got a similar problem as the rest folks here have. Idid as you suggest with the hidden ID variable:
</table>
|;
<input type=hidden name="ID" value="$rec{'ID'}">
}
(I put this at the end of html_record_form)
Now whenever you delete from the middle of the database the next new entry gets screwed .... No ID number. Having the ID's a little screwy (missing numbers in the database due to deletetions) is OK but the next new entry is really bad news. But the second new entry seems fine. I've done all the checking of db_keys and what ever also checked for the and (get defaults) per this thread.

Is there anything I'm missing ????

Also, is there supposed to be a double quote after $rec{'ID'} you didn't add one when you posted this to me.

Thanks
Quote Reply
Re: ID number sorting In reply to
I don't know what the problem is.

Except that you have

</table>
|;
<input type=hidden name="ID" value="$rec{'ID'}">
}

This definitely won't work. Your input field is part of the html code that goes on the page. It must be within the print qq| statement. I'm surprised you didn't get a syntax error.

Try

</table><input type="hidden" name="ID" value="$rec{'ID'}">
|;
}

Quote:
Also, is there supposed to be a double quote after $rec{'ID'} you didn't add one when you posted this to me.

Sometimes I make typos. The correct syntax should be

<input type="hidden" name="ID" value="$rec{'ID'}">

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





Quote Reply
Re: ID number sorting In reply to
Posting a URL to the config file and the html.pl file will help track down this bug!

Cheers,

Alex
Quote Reply
Re: ID number sorting In reply to
Yep, strange things do happen. NO, I only got errors when I tried to put it elsewhere.

JP, it worked. No more blanlk ID spots in the data. Jee, I'm happy today. don't worry about the typo, I was happy that I could do something on my own once in a while Smile Gee, I'm learning so much by screwing up my dbman and then bugging you to fix it again.

Thanks

[This message has been edited by jdunes (edited March 31, 1999).]
Quote Reply
Re: ID number sorting In reply to
Greetings again. Okay, I am also experiencing the same difficulty. I have been racking my brain and fingers for the past two hours testing and trying to fix this problem. I, too added a bunch of test records and then deleted them. When I try to re-add them, I noticed that the 'default.count' file was not holding accurate numbers. (I did verify that the permissions were set properly for the 'default.count' file.)

In the 'db.cgi' file, I have the &get_defaults value set to '+1'. In the 'default.cfg' file I have the following settings:

$db_key = 'ID';
$db_key_track = 1;

In the 'html.pl' I do have the following codes in place:

|; &html_record_form (&get_defaults); print qq|

in the html_add_form sub-routine.

I do not know what the problem is. Could it be that I have the %db_def variables incorrectly configured in the 'default.cfg' file?

Here are my %db_def configurations:

%db_def = (
ID => [0, 'numer', 4, 4, 1, '', ''],
First_Name => [1, 'alpha', 40, 255, 1, '', ''],
Last_Name => [2, 'alpha', 40, 255, 1, '', ''],
Department => [3, 'alpha', 40, 255, 1, '', ''],
Courses => [4, 'alpha', 40, 255, 0, '', ''],
Subjects => [5, 'alpha', 40, 255, 0, '', ''],
Position => [6, 'alpha', 40, 255, 0, '', ''],
Phone => [7, 'numer', 3, 3, 1, '', ''],
URL => [8, 'alpha', 40, 255, 0, '', ''],
Email_Address => [9, 'alpha', 40, 255, 0, '', ''],
Employee_Type => [10, 'alpha', 0, 255, 1, '', ''],
Location => [11, 'alpha', 0, 255, 1, '', ''],
);

and here the variable settings at the bottom of the file:

foreach (sort { $db_def{$a}[0] <=> $db_def{$b}[0] } keys %db_def) {
push (@db_cols, $_);
$db_sort{$_} = $db_def{$_}[1];
$db_form_len{$_} = $db_def{$_}[2];
$db_lengths{$_} = $db_def{$_}[3];
$db_not_null{$_} = $db_def{$_}[4];
$db_defaults{$_} = $db_def{$_}[5];
$db_valid_types{$_} = $db_def{$_}[6];

($_ eq $db_key) and $db_key_pos = $db_def{$_}[0];

Any advice on how to solve this problem would be greatly appreciated. It is not that big of deal for web visitors since I do not have the ID number listed with records. (BTW: I did
insert <input type="hidden" name="ID" value="$rec{'ID'}"> into the sub html_record.)

Here are URLs to our files:

default.cfg
http://www.coco.cc.az.us/cgi-bin/dbman/default.cfg

html.pl
http://www.coco.cc.az.us/cgi-bin/dbman/html.pl

db.cgi
http://www.coco.cc.az.us/cgi-bin/dbman/db.cgi

To view our Employee Directory, visit this web page:

http://www.coco.cc.az.us/cgi-bin/dbman/db.cgi

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: ID number sorting In reply to
What do you mean by
Quote:
I noticed that the 'default.count' file was not holding accurate numbers.

What exactly are you seeing in your records?

I was not able to access any of your scripts. You need to place them in a web-accessible directory and rename them with a .txt extension before I can read them. Also, I couldn't check out your ID number problem, since logging on with "guest/guest" only let me see the search form (no ID field) and the search results (no IDs on the results).

Quote:
It is not that big of deal for web visitors since I do not have the ID number listed with records.

Well, if the ID isn't being added to the record, this will cause you problems later on. If it's just that your numbers are not starting with 1 or something, that's something you can change by editing the default.count file.


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





Quote Reply
Re: ID number sorting In reply to
I guess I did not make myself clear. I apologize. Also, I neglected to save the files as text files and give the appropriate URL. I will try to do that when I return from a Conference this weekend.

The problem is that when I delete a record, let's say records with ID numbers 7-10, and there is a total number of 12 original records, and try to add a new record, I get a ID number of 13 rather than 10. In other words, I delete 3 records out of a total of 12 records, leaving me with 9. The next record should be 10, but it turns up with an ID of 13 in the ADD Form.

The reason that I disabled the ID number from being publicly posted is that it confuses people. Since the main purpose of the Employee Directory is to show personnel information, ID numbers are unnecessary.

I appreciate your comments and analysis. I guess the problem is that in order for the ID number system to work properly, they have to be posted publicly. Yes, that is what I have had to do, which is manually editing the default.count file. This is a major pain in the tush. I was just wondering if there is a way to NOT show the ID # publicly, but have it show up in administrative forms. It is nice that to search through records by ID and delete/modify them.

But I may have to just publicly show the ID#.





------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: ID number sorting In reply to
 
Code:
|; # to close off a previous print qq| statement
if ($per_admin) {
print qq|[a label and field for ID]|;
}
else {
print qq|<input type="hidden" name="ID" value="$rec{'ID'}">|;
}
print qq|

And then continue with the rest of your form definition.

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