PHP to insert ID in table.

jh

Member
Hi

I have been using a calc element to show the ID of a record with a letter appended to the start (egA10) etc in details view.

This works fine but I think it is better for my purposes to set this value by PHP so it is stored not calculated on the fly. I have tried to do this by a php event on list load but I can not get it to return any value. So what I was hoping to find is:

1. How to insert the value of the ID field of a table into another field on the same table.
2. How to append a value to the value returned (eg A, B etc)

Thank you for any assistance.

Kind Regards
 
I have been using a calc element to show the ID of a record with a letter appended to the start (egA10) etc in details view.

There is a relatively new element called 'sequence' which is designed specifically to do that.

If you do a github update, then Discover in J!'s extension manager, you should be able to install, enable and use it. The tooltips on the options explain how it works.

There's basically two modes - one uses the rowid of the element's own data table (but then has the chicken-and-egg issue of not being able to display the sequence in a new form), the other mode uses a separate #__fabrik_sequence table to store a unique sequence number. Both modes allow you to specify the pattern to use (like prefix "A").

-- hugh
 
Hi

Thank you, the sequence element seems to be working great. As Ive added this after some records have already been submitted (so there is no sequence value for these), is there a quick way to update all records or will i need to save each record again?

Many thanks.
 
I think you'd have to edit and save them.

If you are using the PK based method, so it's saving the value in the field itself (rather than our separate table), and you have a lot of records to deal with, you could run a query by hand in phpMyAdmin (or whatever), like ...

Code:
UPDATE mytable SET my_sequence_element = CONCAT('ABC', LPAD(id, 5, 0));

... or whatever CONCAT you need to build the sequence. The example I gave would give you a 0 padded string like ABC00001.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top