Hi, You can just do an UPDATE: UPDATE $table set total_clicked = total_clicked+1
Regards rory oconnor wrote : > > I'm setting up some tracking stats for (opt-in) e-mail campaigns, and > one of the things I'm tracking is click-thrus. I'm going to re-direct > traffic thru a script that will just count the number of clicks, and > store that number in a mysql table. > > It needs to be fast and efficient, and I'm somewhat of a mysql newbie, > so I was wonderinf if there is any more efficient way to simply add a > number to the existing number in that table with mysql and perl. My way > seems like a lot of code to do a little task. Any help is appreciated! > > # set up the db connection and SQL > $dbh = > >DBI->connect("DBI:mysql:database=$database;host=$host","$user","$mysqlpassword",{'RaiseError'=>1}); > $select_number = "select total_clicked from $table"; > > # actually execute the checking query > $sth = $dbh->prepare("$select_number"); > if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } > if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } > > # loop thru the query and set the result variables > while (my $ref = $sth->fetchrow_arrayref) { > $total_clicked = $$ref[0]; > } > > # add 1 to total_clicked > $total_clicked=$total_clicked+1; > > # update the number > $update_number = "UPDATE $table set total_clicked = $total_clicked"; > > # actually execute the update query > $sth = $dbh->prepare("$update_number"); > if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } > if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php -- Joseph Bueno NetClub/Trader.com --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php