Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Parse Links ID number to email-add.txt?

Quote Reply
Parse Links ID number to email-add.txt?
I want to let people know their Links ID number. So I add a line in email-add.txt:
ID: <%ID%>
However, it didn't parse the right ID number.

No matter how many links I already have in my Links table, if there are 1 link to validate(in the Validate table), the ID number will always be 1. If there are 2 links to validate, the ID number will be 1 and 2, respectively.

Does anyone know how to do it? Thanks.
Quote Reply
Re: Parse Links ID number to email-add.txt? In reply to
I wrote a message saying why it probably wasn't possible, then wondered if a function existed to allow finding the last autoinsert ID.

Sure enough... from the MySQL docs:


Code:
LAST_INSERT_ID([expr])
Returns the last automatically-generated value that was set in an AUTO_INCREMENT column. See section 18.4.27
mysql_insert_id().

mysql> select LAST_INSERT_ID();
-> 1

The last ID that was generated is maintained in the server on a per-connection basis. It will not be changed by another client. It will not
even be changed if you update another AUTO_INCREMENT column with a non-magic value (that is, a value that is not NULL and not 0).
If expr is given in an UPDATE clause, then the used value is returned as a last_insert_id value. This can be used to simulate sequences:
First create the table:

create table sequence (id int not null);
insert into sequence values (0);

This can now be used to generate sequence numbers with:

UPDATE sequence SET id=last_insert_id(id+1);

The new id can be read as you would read any normal auto_increment value in MySQL (For example LAST_INSERT_ID() will
return the new id).

------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/








Quote Reply
Re: Parse Links ID number to email-add.txt? In reply to
Try adding in admin.cgi around line 228 right after:

$result = $db->add_record ( \%{$links{$id}} );
$result or ($error{$id} = "<li>$id Couldn't add: '$t' $Links: BSQL::error") and next;

add:

$links{$id}->{ID} = $result;

and I think that should work.

Cheers,

Alex
Quote Reply
Re: Parse Links ID number to email-add.txt? In reply to
Alex, Thank you!
It works.