Gossamer Forum
Home : Products : DBMan : Customization :

simple vote counter

Quote Reply
simple vote counter
Hi,

I was wondering if anyone could give me pointers for a simple vote counter, where clicking a "submit" button in a displayed record would increment the count field for that record by one. I only allow people to modify their own record, so is there a way around it to allow anyone to vote for anyone? If this has been mentioned before, please point me to the thread because I cannot find it. Thanks!

Cary
Quote Reply
Re: simple vote counter In reply to
Not really a "vote" counter...But you can search this forum for "counter" "hit". oldmoney just posted a Thread yesterday that relates to your request.

Another suggestion...look at the rate.cgi script that comes with LINKS. That might also provide you a good model to use for this.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
http://www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------





Quote Reply
Re: simple vote counter In reply to
Hi Eliot,

Yes I checked out the code posted recently, but I'm having troubles getting it to work. I'm posting it again for reference here:
Code:
open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
++$rec{'Teller'};
$output .= &join_encode(%rec);
}
else {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB;

I put this code in sub add_vote in db.cgi, and I added the Teller field to default.cfg as a hidden field that sets it to 0 when a user adds a record. Then to vote, there is a link to (blah)db.cgi?uid=default&add_vote=1&$db_key=(id number). Can you please tell me what I'm doing wrong? Thanks!

Cary
Quote Reply
Re: simple vote counter In reply to
Just clarifying my other post: I put this in a new sub, so rather than counting (incrementing) hits of record displays, it counts clicks on the links to the new sub. Can anyone please suggest how to modify the code so I can achieve this? The sub has to disregard any authentication, and I need to be able to link into it via a $db_key.

Cary

[This message has been edited by blink101 (edited January 25, 2000).]

[This message has been edited by blink101 (edited January 25, 2000).]
Quote Reply
Re: simple vote counter In reply to
This counter mod Carol gived me a couple of months ago. I had to put this in my sub 'html_record_long' in my 'htmp.pl' file.
Quote Reply
Re: simple vote counter In reply to
Hi Mart,

I'm assuming you have implemented the html_record_long mod. I copied this sub (html_record_long) since I don't use it, added the hit counter sub to it, and am trying to call it via the browser. So it thinks it's getting a page, but instead it's just recording a hit in the field Teller. I've tried url/db.cgi?db=default&uid=default&html_long_record=1&ID=(number), and it's not working. I'm wondering what I need to modify or if the call I'm making is even allowed. Thanks.

Cary
Quote Reply
Re: simple vote counter In reply to
Is the reason no one is responding to this because no one knows?